开发者

How to make jmunit run all tests and still fail at the end if any tests failed

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜