Using an ANT script to run JUnit tests, one group of tests (TestSCF) is a subset of all tests. These tests are to be run as part of a nightly build and produce a report. Using @IncludeCategory to define the tests that need to be run, and ClasspathSuite to locate all tests in the project.
An example test class declaration, defined to be run as the TestSCF subset. TestSCF is an empty interface.
@Category(TestSCF.class)
public class ErrorDialogTest extends TestCase
{
....
}
The main test suite.
@RunWith(Categories.class)
@IncludeCategory(TestSCF.class)
@SuiteClasses({AllTests.class})
public class SCFTests
{
}
The AllTests declaration
@RunWith(ClasspathSuite.class)
public class AllTests
{
}
The relevant parts of the ANT script
<!-- Run the unit tests -->
<junit showoutput ="true"
printsummary = "yes"
fork = "yes"
timeout = "60000" >
<formatter type="xml"/>
<classpath refid="cpath"/>
<batchtest fork = "yes"
todir = "${test.report.dir}">
<fileset dir="${src.dir}">
<include name="**/SCFTests.java"/>
</fileset>
</batchtest>
</junit>
<!-- Copy the XML files that get deleted by junitreport -->
<mkdir dir="${junit.html.dir}/xml_files"/>
<copy todir="${junit.html.dir}/xml_files" preservelastmodified="true">
<fileset dir="${test.report.dir}">
<include name="*.xml"/>
</fileset>
</copy>
<!-- Format the test results into browsable HTML -->
<junitreport todir="${junit.html.dir}">
<fileset dir="${test.report.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.html.dir}"/>
</junitreport>
The problem is that the Junit report shows only one class tested – SCFTests. I understand why this is happening, but would like to know if there is a way to produce a report for each class actually tested, or a way to get the name of the class tested added to the ‘name’ of the test results in the report.
For example:
dev.sca.test.ErrorDialogTest 45 Passed, 3 Failures, 0 Errors
as opposed to
SCFTests 45 Passed, 3 Failures, 0 Errors
For future reference, I was able to get the classpath printed in the ‘Name’ column of the report by modifying the junit-frames.xsl file as below.
Under
Becomes
Results in: