Tycho: How to prevent deployment in case of JUnit test failures?
I got an eclipse-plugin
with some unit tests.
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 ".t开发者_高级运维ests"
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...
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.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<deployAtEnd>true</deployAtEnd>
</configuration>
</plugin>
If you don't ignore failures in your test and if some appears the build fail, no artifacts going to be deployed.
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.
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 with mvn 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.)
精彩评论