Daedalos JUnit Extensions Quickstart
Using Extensible Test Cases (XTCs):
- XTCs are typically external tools which return values have to be analysed.
- Interface to access external tool is important.
- XTC methods:
- setUpForTest() - sets up the fixture, e.g. a network connection.
- test*() - sets up the objects needed for the test.
- runTestSilently() - runs the actual test.
- postProcessTest() - evaluates the test result.
- setExpctedResult() - sets the expected result.
Encapsulate primitive types here by their corresponding wrapper classes.
- Build your own XTC:
- Consider which tool you would like to interface to JUnit.
- Define the XTC subclass.
- Override the methods necessary to
- set up the data,
- call the test engine,
- evaluate the results.
Have a look at our XTCs:
External Program Test Case
- All you have to do to create a new unit test using an external program is to subclass com.daedalos.junit.tests.ExternalProgramTestCase
and to add your test functionality:
- Define your own subclass MyExample extends ExternalProgramTestCase.
- Define your test method:
public void testMyExternalProgram() {
this.setFilename("myExternalProgram.exe");
//Program name [and location]
that should be executed.
this.setOutputFilename("ExternalProgramOutput.txt");
//Optional: To store the
external program screen output,
//set the filename [and location] where this information
//should be stored.
this.setExpectedResult(0);
//Set the expected exit code.
}
- See also the provided example ExampleExternalProgramTest.
Class Locator Test Case
- This XTC checks if a class definition is found in a specific JAR file or directory. All you have to do is to subclass
com.daedalos.junit.tests.ClassLocatorTestCase
and to add your test functionality:
- Define your own subclass MyExample extends ExternalProgramTestCase.
- Define your test method:
public void testMyClasspath() {
//Some initializations
String userDir = System.getProperty("user.dir");
String fileSeparator = System.getProperty("file.separator");
//Specify the class that should be checked
this.setLocateClass("junit.framework.TestCase");
//Set the location where you expect that the class is read from
this.setExpectedResult(userDir + fileSeparator + "lib" + fileSeparator + "junit.jar");
}
- See also the provided example ExampleClassLocatorTest.
(C)opyright 2001-2006 by Jens Uwe Pipka, Germany. Contact: jens-uwe.pipka@jup-net.de