20

次のようなターゲットを使用して、Ant 経由で JUnit を実行しています。

<target name="junit" depends="compile">
    <mkdir dir="${report.dir}"/>
    <junit printsummary="yes" haltonfailure="yes" showoutput="yes" >
        <classpath>
            <path refid="classpath"/>
            <path location="${classes.dir}"/>
        </classpath>
        <formatter type="brief" usefile="false"/>
        <formatter type="xml"/>

        <batchtest fork="yes" todir="${report.dir}">
            <fileset dir="${src.dir}" includes="**/*Tests.java" />
        </batchtest>
    </junit>
</target>

私はこのようなクラスを持っています:

public class UserTests extends TestCase {

    public void testWillAlwaysFail() {
        fail("An error message");
    }
    public void testWillAlwaysFail2() {
        fail("An error message2");
    }
}

haltonfailure="yes"単一のテストが失敗するとすぐにビルドが停止し、最初に失敗したテストのみがログに記録されるようです。「オフ」に設定すると、ビルド全体が成功します (テスト失敗メッセージが出力に書き込まれます)。

すべてのテストを実行し (失敗した場合でも)、テストが失敗した場合はビルドを停止する必要があります。

これを行うことは可能ですか?

4

1 に答える 1

43

failurepropertyタスクの属性を設定してからjunit、後でfailタスクを使用してプロパティをテストできます。

<junit haltonfailure="no" failureproperty="test.failed" ... >
   ...
</junit>
<fail message="Test failure detected, check test results." if="test.failed" />
于 2010-10-27T23:43:29.603 に答える