Android JUnit 测试失败,没有像我预期的那样破坏我的 Ant 脚本?
JUnit 测试失败,没有像我期望的那样破坏我的 Ant 脚本?
我的持续集成服务器运行一个 Ant 脚本,它调用如下内容: /tests/ant run-tests
我的 JUnit 测试运行,但出现错误: 运行测试: [echo] 运行测试助手。 [回声] 运行测试... [执行] [执行] com.zedray.stuff.FooBarTest:.... [exec] com.zedray.stuff.FooBarTest:.....INSTRUMENTATION_RESULT:shortMsg=您的代码中出现一些错误。 [exec] INSTRUMENTATION_RESULT:longMsg=java.security.InvalidParameterException:代码中出现一些错误 [exec] INSTRUMENTATION_CODE: 0
错误没有问题,但我的构建脚本继续运行(最终将我损坏的应用程序发布给我的测试人员 - 糟糕!)。我期望仪器抛出构建错误,因此我的持续集成服务器(在本例中为 TeamCity)意识到出现了问题并报告损坏的构建。 “failonerror”已经在相关的宏定义中设置,所以我不确定我还能做什么?
/tests/build.xml运行测试...
关于如何解决这个问题有什么想法/建议吗?
问候 标记
Failing JUnit tests, not breaking my Ant script like I expect?
My continuous integration server runs an Ant script, which calls something like:
/tests/ant run-tests
My JUnit tests run, but with errors:
run-tests:
[echo] run-tests-helper.
[echo] Running tests ...
[exec]
[exec] com.zedray.stuff.FooBarTest:....
[exec] com.zedray.stuff.FooBarTest:.....INSTRUMENTATION_RESULT: shortMsg=Some error in your code.
[exec] INSTRUMENTATION_RESULT: longMsg=java.security.InvalidParameterException: Some error in your code
[exec] INSTRUMENTATION_CODE: 0
The errors are OK, but my build script keeps going (eventually publishing my broken app to my testers - bad!). What I would expect is for the instrimentaiton to throw a build error, so my continuous integration server (TeamCity in this case) realises that something has gone wrong and reports a broken build. The "failonerror" is already set in the relevant macrodef, so I'm not sure what else I can do?
/tests/build.xml
Running tests ...
Any ideas/suggestions on how to fix this?
Regards
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我采用了另一种方式,因为我使用的是 Android
build.xml
文件中的 anttest
目标。该目标打印到标准输出,因此我将标准输出捕获到文件中,然后查询该文件,使用此结果使我的任务失败。I did it another way, because I am using the ant
test
target that is in the Androidbuild.xml
file. This target prints to the standard out, so I captured stndout into a file then queried the file, using this result to fail my task.我遇到了同样的问题,我最终像这样在自己的 build.xml 中自定义了“run-tests”目标,并且不需要更改原始的 android sdk test_rules.xml
I had the same problem, and I ened up customize the "run-tests" target in my own build.xml like this, and there is no need to change the original android sdk test_rules.xml
还为此寻找某种标准解决方案。我想知道android们是如何开发的,或者他们不使用teamcity和持续集成?听说 hudson 有一些 Android 插件,但我不喜欢 hudson。无论如何,这是快速而肮脏的解决方案,
将 android-sdk-windows\tools\ant\test_rules.xml 中的内容替换为:
有两个缺点
1)当测试运行时,你看不到测试输出,直到测试失败(并且输出以某种方式被削弱)
2)最好在你的项目中覆盖这个宏
Also was looking for some kind of standard solution for this. I wonder how do android guys develop, or they dont use teamcity and continuous integration? heard hudson has some plugin for android but I dont like hudson. anyway here is quick and dirty solution
replace contents in android-sdk-windows\tools\ant\test_rules.xml with:
there are two drawbacks
1) you dont see test output while tests are running until they failed (and the output is crippled somewhow)
2) its better to override this macro in your project
当然,另一种选择是放弃 Ant,转而使用 Maven 或 Gradle。两者都有 Android 插件,可以在测试失败时正确地使构建失败。
行家:
http://code.google.com/p/maven-android-plugin/
摇篮:
http://code.google.com/p/gradle-android-plugin/
运行仪器测试刚刚添加到 Gradle Android 插件中,正在等待合并回主存储库,因此应该很快就会有另一个版本。
another option would of course be to ditch Ant in favor of Maven or Gradle. Both have Android plug-ins that properly fail the build when there are test failures.
Maven:
http://code.google.com/p/maven-android-plugin/
Gradle:
http://code.google.com/p/gradle-android-plugin/
running instrumentation tests has just been added to the Gradle Android plug-in, and is waiting to be merged back into the master repository, so there should be another release soon.
ant JUnit 任务 默认运行所有测试。对此有两种解决方案。
最简单的解决方案是将 haltonerror 属性设置为 true,构建将在第一次测试失败时失败。
稍微复杂一些(也是我的偏好)是设置failureProperty,以便所有测试都能运行。这可以让您知道有多少测试失败,而不仅仅是第一个失败的测试。这需要更多的 ant 工作,因为您需要在 junit 测试后添加一行,如下所示:
The ant JUnit task defaults to running all the tests. There are two solutions to this.
Easiest solution is to set the
haltonerror
property to true and the build will fail at the first test failure.Slightly more involved (and my preference) is to set the
failureProperty
so that all the tests run. This lets you know how many tests fail instead of only the first test that fails. This requires more ant work because you need to add a line after your junit tests like this: