2009-06-19 20 views

答えて

14

は、例えば、あなたがfailurePropertyを設定することができます

<target name="otherStuff" if="test.failed"> 
    <echo message="I'm here. Now what?"/> 
    <fail message="JUnit test or tests failed."/> 
</target> 

最後に、それらを結びつける:

<target name="test" depends="junit,otherStuff"/> 

次​​に、testターゲットを呼び出して、JUnitテストを実行します。 junitターゲットが実行されます。失敗した場合(失敗またはエラー)、test.failedプロパティが設定され、otherStuffターゲットの本体が実行されます。

javacタスクは、同様の動作を得るために使用できるfailonerrorおよびerrorProperty属性をサポートしています。カイから述べたように

1

ant-contribには、trycatchタスクがあります。

+0

悲しいことに、私はまだビルドが失敗したいので、うまくいきません。 – tomjen

0

失敗をチェックするタスクにプロパティを設定し、プロパティが設定されていない場合に実行されるように2番目のタスクを書き込みます。私はbuild.xmlのための正確な構文を覚えていない、または私は例を与えるだろう。 test.failedプロパティが設定されている場合のみ実行ターゲットを作成し、その後

<target name="junit" depends="compile-tests" description="Runs JUnit tests"> 
    <mkdir dir="${junit.report}"/> 
    <junit printsummary="true" failureProperty="test.failed"> 
     <classpath refid="test.classpath"/> 
     <formatter type="xml"/> 
     <test name="${test.class}" todir="${junit.report}" if="test.class"/> 
     <batchtest fork="true" todir="${junit.report}" unless="test.class"> 
      <fileset dir="${test.src.dir}"> 
       <include name="**/*Test.java"/> 
       <exclude name="**/AllTests.java"/> 
      </fileset> 
     </batchtest> 
    </junit> 
</target> 

が、最後に失敗します:あなたのjunitターゲットで

6

ant-contribはtrycatchタスクを持っています。

しかし、最近のバージョン1.0b3が必要です。そして使用してください

<trycatch> 
    <try> 
     ... <!-- your executions which may fail --> 
    </try> 
    <catch> 
     ... <!-- execute on failure --> 
     <throw message="xy failed" /> 
    </catch> 
</trycatch> 

トリックは、壊れたビルドを示すためにもう一度エラーをスローすることです。

関連する問題