Skip to content

Commit d03c083

Browse files
matthijskooijmancmaglie
authored andcommitted
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 0641cd7 commit d03c083

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

app/build.xml

+41-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,41 @@
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 full details to stdout when running a single test -->
141+
<formatter type="plain" usefile="false" if="single-test-class"/>
142+
<!-- When running all tests, print details for failing tests and a summary for each test class (printsummary=yes above) -->
143+
<formatter type="brief" usefile="false" unless="single-test-class"/>
144+
145+
<!-- When both single-test-class and single-test-methods are specified, pass both to unit -->
146+
<test name="${single-test-class}" methods="${single-test-methods}" todir="${test.reportdir}" if="single-test-methods"/>
147+
<!-- When just single-test-class is specified, omit methods to run the entire class -->
148+
<test name="${single-test-class}" todir="${test.reportdir}" if="single-test-class" unless="single-test-methods"/>
149+
<!-- When neither are specified, run *all* testcases -->
150+
<batchtest fork="yes" todir="${test.reportdir}" unless="single-test-class">
127151
<fileset dir="test">
128152
<include name="**/*Test.java"/>
129153
<exclude name="**/Abstract*.java"/>
130154
</fileset>
131155
</batchtest>
132156
</junit>
133157

158+
<!-- Convert generated XML reports to browsable HTML -->
159+
<junitreport todir="${test.reportdir}">
160+
<fileset dir="${test.reportdir}">
161+
<include name="TEST-*.xml" />
162+
</fileset>
163+
<report todir="${test.htmldir}" />
164+
</junitreport>
165+
166+
<!-- 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. -->
167+
<property name="test.htmldir.display" location="${test.htmldir}" relative="true" basedir="${user.dir}"/>
168+
<property name="test.reportdir.display" location="${test.reportdir}" relative="true" basedir="${user.dir}"/>
169+
<echo message="Detailed test results can be found in ${test.reportdir.display}"/>
170+
<echo message="A browsable HTML summary is generated in ${test.htmldir.display}/index.html"/>
171+
134172
<fail if="test.failed"/>
135173
</target>
136174

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)