JUnit 测试失败,没有像我预期的那样破坏我的 Ant 脚本?
我的持续集成服务器运行一个 Ant 脚本,它调用如下内容: /tests/ant 运行测试
我的 JUnit 测试运行,但有错误: 运行测试: [echo] 运行测试助手。 [echo] 运行测试... [执行] [执行] com.zedray.stuff.FooBarTest:.... [exec] com.zedray.stuff.FooBarTest:.....INSTRUMENTATION_RESULT: shortMsg=您的代码中存在一些错误。 [exec] INSTRUMENTATION_RESULT:longMsg=java.security.InvalidParameterException:您的代码中存在一些错误 [执行] INSTRUMENTATION_CODE: 0
错误正常,但我的构建脚本继续运行(最终将我损坏的应用程序发布给我的测试人员 - 糟糕!)。我期望的是 instrimentaiton 抛出一个构建错误,所以我的持续集成服务器(在这种情况下是 TeamCity)意识到出了点问题并报告构建失败。 “failonerror”已经在相关的 macrodef 中设置,所以我不确定我还能做什么?
/测试/build.xml运行测试...
关于如何解决这个问题有什么想法/建议吗?
问候 标记
最佳答案
我是用另一种方式做的,因为我使用的是 Android build.xml
文件中的 ant test
目标。这个目标打印到标准输出,所以我将 stndout 捕获到一个文件中,然后查询该文件,使用这个结果使我的任务失败。
<target name="run-acceptance-tests" depends="clean, debug, install" >
<property name="log.file" value="acceptance_tests_standard_out.txt" />
<!-- because we don't have control over the 'test' target (to check for passes an fails) this prints to standard out
we capture standard out into a file and query this to see if we have any test failures, using this to pass/fail our task -->
<record name="${log.file}" action="start" />
<antcall target="test" />
<record name="${log.file}" action="stop" />
<!-- do other stuff -->
<loadfile property="tests.output" srcFile="${log.file}" />
<echo>Checking for failures</echo>
<fail message="acceptance tests failed!" >
<condition>
<contains string="${tests.output}" substring="FAILURES" />
</condition>
</fail>
<echo>acceptance tests passed!</echo>
</target>
关于android - Android JUnit 测试失败,没有像我预期的那样破坏我的 Ant 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2959500/