When开发者_如何学C I switch off haltonfailure
or haltonerror
in my jmunit tests like this:
<jmunit haltonerror="false" haltonfailure="false" failureproperty="testfailure">
<formatter type="xml" />
<classpath>
<path path="${jar_location}" />
<path path="${build}" />
</classpath>
<!-- Add -->
<test name="com.example.tests.Test1" todir="${reports}" />
<test name="com.example.tests.Test2" todir="${reports}" />
<test name="com.example.tests.Etc" todir="${reports}" />
</jmunit >
The build succeeds even when some tests failed. If I turn the halts on, then of course it halts immediately upon the first failure. The behaviour I want is that all tests are executed regardless of how many of them fail, but if ANY of them failed then the build won't be successful. The reason I want this is so that the reports can correctly show how many passes and failures, and which tests are failing.
How do I achieve this? and/or Is my thinking that I want all of the tests to be run flawed?
Easy peasy:
You need to add the command
<fail message="Something went wrong. Please check the test results." if="testfailure" />
to the target that contains your jmunit command after the jmunit command itself.
This way, the jmunit task will set the variable testfailure
when one of the tests fails and the command fail
will make the build unsuccessful if that property is set.
Hope that helps.
精彩评论