Tycho:如果 JUnit 测试失败,如何防止部署?
我有一个带有一些单元测试的 eclipse-plugin
。
在 Maven 中,我将单元测试保留在同一个包中,并在 pom.xml
中指定 junit 作为测试依赖项。
现在我想切换到第谷,我读到第谷正在寻找一个具有相同名称的包以及一个被执行的后缀“.tests”
。但我想将我的单元测试保留在已测试的捆绑包中,以便如果任何测试失败,捆绑包的构建都会失败。否则,maven 可能会在单元测试未成功完成的情况下安装/部署工件。
有没有办法使用 tycho 将单元测试保留在同一个包中?
如何管理第谷构建中的单元测试?
更新: 好的,我现在有两个单独的包,一个 eclipse-plugin
和一个 eclipse-test-plugin
。第谷在同一个反应器中构建它们,但尽管单元测试失败了,但我的 eclipse-plugin 仍被部署。现在我的 Nexus 仓库中出现了一个损坏的工件...
当单元测试未成功完成时,有没有办法强制构建失败?
I got an eclipse-plugin
with some unit tests.
In maven I kept the unit tests in the same bundle and specified junit as testing dependency in the pom.xml
.
Now I want to switch to tycho and I read that tycho is looking for a bundle with the same name plus a postfix ".tests"
which gets executed. But I would like to keep my unit tests in the tested bundle so that the build of the bundle will fail if any test fails. Otherwise maven might install/deploy artifacts where the unit tests haven't completed successfully..
Is there a way to keep the unit tests in the same bundle using tycho?
How do you manage unit tests in tycho builds?
Update: Ok I got now two separate bundles an eclipse-plugin
and an eclipse-test-plugin
. Tycho builds them both in the same reactor but my eclipse-plugin
gets deployed although the unit-tests have failed. Now I got a broken artifact in my nexus repo...
Is there a way to enforce a buildfailure when the unit tests didn't complete successfully?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这个话题很老了,但我找到了一个如此简单的解决方案。
您可以配置要在构建结束时部署的工件。
如果您不忽略测试中的失败,并且如果某些出现构建失败,则不会部署任何工件。
I know this topic is old, but I found such a simple solution.
You can configure that the artifacts going to be deployed at the end of the build.
If you don't ignore failures in your test and if some appears the build fail, no artifacts going to be deployed.
单元测试不能保存在同一个包中,因为 tycho 使用 MANIFEST-first 方法来处理依赖关系。
如果您将测试和生产代码放在同一个包中,那么您的生产包可能会被测试范围的依赖项(例如 junit)污染。
与 Maven 不同,OSGi 没有依赖项的“范围”属性。
unit tests can't be kept in the same bundle because tycho uses a MANIFEST-first approach to dependencies.
You would pollute your productive bundle with test-scoped dependencies such as junit if you kept tests and productive code in the same bundle.
Unlike maven, OSGi has no "scope" attribute for dependencies.
这实际上是第谷的一个限制:你不能在同一个模块中包含测试和生产代码,因此如果你调用
mvn clean deploy
,生产工件会在执行相应的测试之前部署。要仅在成功执行测试后进行部署,有一个简单的解决方法:首先使用
mvn clean verify
运行所有测试,并且仅在成功时使用mvn 运行构建再次干净部署。 (如果您的测试不稳定,您甚至可能需要在第二次调用中使用
-DskipTests
禁用测试执行,以确保您不会获得部分部署。)This is in fact a limitation in Tycho: You can't have tests and the productive code in the same module, so if you call
mvn clean deploy
, the productive artifact is deployed before its corresponding tests are executed.To only deploy after successful test execution, there is a simple workaround: first run all tests with
mvn clean verify
, and only if that succeeds run the build withmvn clean deploy
again. (In case you have unstable tests, you may even want to disable test execution with-DskipTests
in the second call to be really sure you don't get a partial deployment.)