Getting Started with xDriveUnit

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.

Step 1: Create the test case

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 junit.framework.Test;

import com.flexiblewebsolutions.exceptions.MissingConfigException;
import com.flexiblewebsolutions.xdriveunit.XDriveTestCase;

public class XMLDrivenTest extends XDriveTestCase
The following methods are required by every class that will use the framework:

2 Constructor methods must be overridden as each has their own purpose:
    public XMLDrivenTest( String pName, StringBuffer pTestInput,
            StringBuffer pTestOptions, String pThreadName ) {
        super( pName, pTestInput, pTestOptions, pThreadName );

    public XMLDrivenTest() {
The suite method with no arguments is what will be called by default when the testclass is run through an IDE or CruiseControl. You can implement this to run a default configuration. The other suite methods are required but the implementation should follow the example below but with your test class listed

    public static Test suite() {
        return ( suite( "testConfig/decorators.xml" ) );

    public static Test suite( String pConfigFile ) {
        try {
            return ( new XMLDrivenTest().init( pConfigFile ) );
        catch( MissingConfigException e ) {
            return null;

    public static Test suite( StringBuffer pConfigInfo, String pThreadName ) {
        return ( new XMLDrivenTest().init( pConfigInfo, pThreadName ) );
The following method should exist as is:
    public String getClassName() {
        return this.getClass().getName();
The following methods can be implemented by a parent class that you implement and therefore would not be required in each implementing class: Since all your configuration is stored in xml files, this is how you tell the framework how to locate the files. The test directory is the base directory which will be searched.
    public File getTestDirectory() {
    	File testdir = new File( "test" );
        return ( testdir );
The tmp directory is where files generated by the test will be put:
    public File getTestTmpDirectory() {
        return ( new File( getTestDirectory(), "tmp" ) );

Step 2: Creating your XML Config

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"?>
Any number of test classes can be defined in this file.
Each class will need to have:
  1. Class name of the test
  2. Filename where test options are stored
  3. Test methods that exist in the class.
These are defined as follows
Each test method will need to be defined to specify the name of the method in the test class. Also a filename can be entered to point to a data file of which the contents will automatically be available when the test is executed.
Close your XML tags,

Step 3: Running the Test

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.