Skip to content

Commit b9c5559

Browse files
ant: Improve running of testsuite
This allows running an individual test class by specifying -Dsingle-test-class=path.to.Classs and methods within the specified class by specifying -Dsingle-test-methods=testMethod1,testMethod2. Additionally, this improves the error output, but not showing full stderr/stdout output when running the full test suite, and by generating a browsable HTML report with test results (including stdout/stderr output). When single-test-class is used, detailed output (including stdout/stderr) is still printed directly. This also moves the test result XML files into a subdirectory for clarity, which is removed before starting a testrun (so the HTML report does not include older test results).
1 parent 2e7dc85 commit b9c5559

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

Diff for: app/build.xml

+39-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,20 @@
109109
<fileset dir="test" includes="**/*.pac" />
110110
</copy>
111111

112-
<junit printsummary="yes" dir="${work.dir}" fork="true" showoutput="yes" failureproperty="test.failed">
112+
<!-- XML and TXT reports will be written here -->
113+
<property name="test.reportdir" value="test-bin/results"/>
114+
<!-- Summary HTML report will be written here -->
115+
<property name="test.htmldir" value="test-bin/results/html"/>
116+
117+
<!-- Remove the reportdir, so the HTML report only includes tests from this run -->
118+
<delete dir="${test.reportdir}" />
119+
<mkdir dir="${test.reportdir}"/>
120+
<mkdir dir="${test.htmldir}"/>
121+
122+
<!-- Sanity check: when single-test-methods is set, but single-test-class is not, raise an error -->
123+
<fail message="Need single-test-class if single-test-methods is set" if="single-test-methods" unless="single-test-class"/>
124+
125+
<junit printsummary="yes" dir="${work.dir}" fork="true" showoutput="no" failureproperty="test.failed">
113126
<jvmarg value="-Djava.library.path=${java.additional.library.path}"/>
114127
<jvmarg value="-DWORK_DIR=."/>
115128
<jvmarg value="-ea"/>
@@ -121,16 +134,39 @@
121134
<path refid="class.path.test"/>
122135
</classpath>
123136

137+
<!-- Write XML files (for report-generation) and TXT files (for manual review) for every test class -->
138+
<formatter type="plain" />
124139
<formatter type="xml"/>
125-
126-
<batchtest fork="yes" todir="test-bin">
140+
<!-- Print details to stdout when running a single test. Otherwise just a summary is printed for each test class (printsummary=yes above) -->
141+
<formatter type="plain" usefile="false" if="single-test-class"/>
142+
143+
<!-- When both single-test-class and single-test-methods are specified, pass both to unit -->
144+
<test name="${single-test-class}" methods="${single-test-methods}" todir="${test.reportdir}" if="single-test-methods"/>
145+
<!-- When just single-test-class is specified, omit methods to run the entire class -->
146+
<test name="${single-test-class}" todir="${test.reportdir}" if="single-test-class" unless="single-test-methods"/>
147+
<!-- When neither are specified, run *all* testcases -->
148+
<batchtest fork="yes" todir="${test.reportdir}" unless="single-test-class">
127149
<fileset dir="test">
128150
<include name="**/*Test.java"/>
129151
<exclude name="**/Abstract*.java"/>
130152
</fileset>
131153
</batchtest>
132154
</junit>
133155

156+
<!-- Convert generated XML reports to browsable HTML -->
157+
<junitreport todir="${test.reportdir}">
158+
<fileset dir="${test.reportdir}">
159+
<include name="TEST-*.xml" />
160+
</fileset>
161+
<report todir="${test.htmldir}" />
162+
</junitreport>
163+
164+
<!-- Make these paths relative to user.dir, which is the current directory when invoking ant (so the resulting paths are relative to the environment of the user. -->
165+
<property name="test.htmldir.display" location="${test.htmldir}" relative="true" basedir="${user.dir}"/>
166+
<property name="test.reportdir.display" location="${test.reportdir}" relative="true" basedir="${user.dir}"/>
167+
<echo message="Detailed test results can be found in ${test.reportdir.display}"/>
168+
<echo message="A browsable HTML summary is generated in ${test.htmldir.display}"/>
169+
134170
<fail if="test.failed"/>
135171
</target>
136172

Diff for: build/build.xml

+7-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,13 @@
183183
</target>
184184

185185
<target name="subprojects-test">
186-
<subant buildpath="../app" target="test"/>
186+
<subant buildpath="../app" target="test">
187+
<propertyset>
188+
<!-- Forward these to subant. Use propertyset/propertyref instead of a direct property so we do not need to specify a value -->
189+
<propertyref name="single-test-class"/>
190+
<propertyref name="single-test-methods"/>
191+
</propertyset>
192+
</subant>
187193
</target>
188194

189195
<!-- - - - - - - - - -->

0 commit comments

Comments
 (0)