April 2005
Intermediate to advanced
336 pages
7h 20m
English
When you're working with JUnit, you can set up
test suites, which run multiple tests, by extending
the TestSuite class:
import junit.framework.TestCase;
import junit.framework.TestSuite;
.
.
.
public class NewSuite extends TestSuite
{
static public Test testSuite( )
{
TestSuite suite = new TestSuite( );
suite.addTestSuite(Project.class);
suite.addTestSuite(Connector.class);
suite.addTestSuite(DataHandler.class);
return suite;
}
} When you're using JUnit from Ant, it's easier to use
batch testing with the nested batchtest task. This task lets you specify
whole filesets to test using the fileset type, and the results will be merged
into a report. Here's how to use batchtest:
<target name="test6" depends="compile">
<junit printsummary="yes" haltonfailure="yes">
<formatter type="brief" usefile="true"/>
<classpath path="."/>
<batchtest todir="${results}">
<fileset dir="." includes="**/Project.class"/>
</batchtest>
</junit>
</target> In this case, the fileset only contains a single file
(there's only one file to test in this chapter's example), but you can
include as multiple files in your nested fileset element:
<target name="test6" depends="compile">
<junit printsummary="yes" haltonfailure="yes">
<formatter type="brief" usefile="true"/>
<classpath path="."/>
<batchtest todir="${results}">
<fileset dir="${build}">
<include name="**/*Test.class"/>
<include name="**/*Gold.class"/>
<exclude name="**/*Beta.class"/>
</fileset>
</batchtest>
</junit>
</target>Read now
Unlock full access