Issue
I've got a build system running Ant Version 1.10.6 The macrodef that I've summarised below is constructed to switch on "run.multi" either it runs a single test method or it does something else (which i've not included as its not relevant). The issue I have here is that I cannot get it to run just the one method 'test.method' - I've turned the verbose on and can see it all going in and being set correctly, but it runs all the methods regardless!
<echo level="info" message="Single method=@{test.method}" />
<junit printsummary="on" showoutput="true" fork="yes" forkmode="once">
<assertions>
<enable/>
</assertions>
<test unless="${run.multi}"
name="@{test.single}"
methods="@{test.method}"
haltonfailure="no"
haltonerror="no">
<formatter type="plain" usefile="false"/>
</test>
And here is a portion of the output:
[echo] Single method=testSimple
[junit] Running com.test.util.TheTestToRun
[junit] Testsuite: com.test.util.TheTestToRun
[junit] Running on Java 9.0.4
[junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.473 sec
Solution
The reason that this was happening is either a bug or a feature in ant - around the fork option on the junit section. set 'fork=no' and the issue goes away:
<junit printsummary="on" showoutput="true" fork="no" forkmode="once">
<test unless="${run.multi}"
name="@{test.single}"
methods="@{test.method}"
haltonfailure="no"
haltonerror="no">
<formatter type="plain" usefile="false"/>
</test>
A portion of the output:
[junit] Running com.test.util.TheTestToRun
[junit] Testsuite: com.test.util.TheTestToRun
[junit] Running on Java 9.0.4
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.12 sec
Answered By - Rafe
Answer Checked By - David Marino (JavaFixing Volunteer)