This guide will give you an introduction on how to use xdrive unit to start running your junit tests dynamically. For more details please see the Javadocs.
xDriveUnit relies on a series of XML configuration files that are automatically parsed by extending XDriveTestCase and implementing some methods. The following code can be copied and used almost exactly as shown with only some logical replacements. The definition of the file should be like the following:
package test; import java.io.File; import junit.framework.Test; import com.flexiblewebsolutions.exceptions.MissingConfigException; import com.flexiblewebsolutions.xdriveunit.XDriveTestCase; public class XMLDrivenTest extends XDriveTestCase {
public XMLDrivenTest( String pName, StringBuffer pTestInput, StringBuffer pTestOptions, String pThreadName ) { super( pName, pTestInput, pTestOptions, pThreadName ); } public XMLDrivenTest() { super(); }
public static Test suite() { return ( suite( "testConfig/decorators.xml" ) ); } public static Test suite( String pConfigFile ) { try { return ( new XMLDrivenTest().init( pConfigFile ) ); } catch( MissingConfigException e ) { e.printStackTrace(); return null; } } public static Test suite( StringBuffer pConfigInfo, String pThreadName ) { return ( new XMLDrivenTest().init( pConfigInfo, pThreadName ) ); }
public String getClassName() { return this.getClass().getName(); }
public File getTestDirectory() { File testdir = new File( "test" ); return ( testdir ); }
public File getTestTmpDirectory() { return ( new File( getTestDirectory(), "tmp" ) ); } }
The next step is to create your xml configuration which you can use to control your test. This file should be located in the 'test directory' as defined in the getTestDirectory method and the value to be passed in through the suite method. Use the schema definition to ensure that your xml will work correctly with the XDriveUnit framework.
<?xml version="1.0" encoding="ISO-8859-1"?> <testconfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../schemas/XDriveTestCase.xsd">
<classes>
<class> <classname>test.XMLDrivenTest</classname> <testOptionsFileName>LoadTestOptions.xml</testOptionsFileName> <tests>
<test> <testmethod> <inputFileName></inputFileName> <testmethodname>testStuff</testmethodname> </testmethod> </test>
</tests> </class> </classes> </testconfig>
There are a number of ways to run your test. If you have implemented the suite
method with no arguments, you can run the test case from Eclipse by selecting it
and picking the option Run as JUnit Test.
Another option is to have your test run automatically through CruiseControl.