Ответ 1
В вашей junit target, например, вы можете установить failureProperty
:
<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>
Затем создайте цель, которая запускается только в том случае, если установлено свойство test.failed
, но не завершено в конце:
<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
, которые могут использоваться для получения аналогичного поведения.