The AntTaskTest Class

The class org.apache.lenya.cms.task.AntTaskTest tests an AntTask-based task. It ensures that no exception is thrown during execution and that the logfile is created at the appropriate location. To use the AntTaskTest for your specific task, just specify the target as a command line parameter.

Overriding the AntTaskTest

To test your own AntTask-based task, you can extend the class AntTaskTest:

  • To hardcode the target, override getTarget().
  • To add test evaluation code, override evaluateTest().

You can use the following template:

public class MyTest extends AntTaskTest {

    /** Creates a new object. */
    public MyTest(String test) {
        super(test);
    }
    
    /** Creates a test suite. */
    public static Test getSuite() {
        return new TestSuite(MyTest.class);
    }

    /**
     * The main program.
     * @param args The command line arguments
     */
    public static void main(String[] args) {
        AntTaskTest.initialize(args);
        TestRunner.run(getSuite());
    }

    public static final String DOCUMENT_ID = "tutorial";
    
    /** Checks if the test produced the correct results. */
    protected void evaluateTest() throws IOException {
        ...
    }
    
    /** Returns the task parameters. */
    protected Parameters getTaskParameters() {
        Parameters parameters = super.getTaskParameters();
        parameters.setParameter("properties.mytask.documentid", DOCUMENT_ID);
        return parameters;
    }
    
    /** Returns the target to execute. */
    protected String getTarget() {
        return "mytask";
    }
}

Using a Separate TestCase for Evaluation

If you want to write your own TestCase to check if everything is OK, you can use the AntTaskTest class as it is. Just pass the target as a command-line argument and add your TestCase to the same target in test-build.xml.

  • No labels