- Include the ant testunit jar - in a Maven project you can add a dependency such as
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-testutil</artifactId>
<version>1.8.4</version>
<scope>test</scope>
</dependency>
- Extend your test case from org.apache.tools.ant.BuildFileTest
- Write a setup like
@Override
public void setUp()
throws Exception
{
configureProject(
"./build.xml" );
}
- Write your test cases, with the methods starting with "test" (as in the classic JUnit)
public void testAntTask()
throws Exception
{
final File testOutputFile = File.createTempFile("schemacrawler.",
".test");
setAntProjectProperty("outputfile", testOutputFile.getAbsolutePath());
executeTarget("ant_task_test");
System.out.println(getFullLog());
System.out.println(getOutput());
// some asserts here
}
- You can set properties with the utility method
private void setAntProjectProperty(final String name, final String value)
{
final Project antProject = getProject();
antProject.setProperty(name, value);
}