18

Junit 4.4 と Ant 1.7 を使用しています。テスト ケースがエラーで失敗した場合 (たとえば、メソッドが予期しない例外をスローしたため)、エラーの詳細はわかりません。

私のbuild.xmlは次のようになります:

<target name="test" depends="compile">
<junit printsummary="withOutAndErr" filtertrace="no" fork="yes" haltonfailure="yes" showoutput="yes">
  <classpath refid="project.run.path"/>
  <test name="a.b.c.test.TestThingee1"/>
  <test name="a.b.c.test.NoSuchTest"/>
</junit>
</target>

「ant テスト」を実行すると、(たとえば) 2 回のテスト実行、0 回の失敗、1 回のエラーと表示されます。これは完全に合理的であり、エラーの原因を突き止めることができますが、「NoSuchTest のようなテストはありません」とは言いません。

ありがとう!

-ダン

4

2 に答える 2

34

理解した :)

junit ブロック内に「フォーマッター」を追加する必要がありました。

<formatter type="plain" usefile="false" />

なんというピタ。

-ダン

于 2008-11-29T08:14:14.020 に答える
7

多くのテストを行う場合は、次の2つの変更を検討する必要があります。

  1. 最初のエラーで停止するのではなく、すべてのテストを実行します
  2. すべてのテスト結果を示すレポートを作成する

そして、junitreportタスクで行うのは非常に簡単です。

<target name="test">
    <mkdir dir="target/test-results"/>
    <junit fork="true" forkmode="perBatch" haltonfailure="false"
           printsummary="true" dir="target" failureproperty="test.failed">
        <classpath>
            <path refid="class.path"/>
            <pathelement location="target/classes"/>
            <pathelement location="target/test-classes"/>
        </classpath>
        <formatter type="brief" usefile="false" />
        <formatter type="xml" />
        <batchtest todir="target/test-results">
            <fileset dir="target/test-classes" includes="**/*Test.class"/>
        </batchtest>
    </junit>

    <mkdir dir="target/test-report"/>
    <junitreport todir="target/test-report">
        <fileset dir="target/test-results">
            <include name="TEST-*.xml"/>
        </fileset>
        <report format="frames" todir="target/test-report"/>
    </junitreport>

    <fail if="test.failed"/>
</target>
于 2008-11-29T15:30:10.880 に答える