Reputation: 1070
I want to run my Junit on my build jar's, but maven surefire plugin executed on class file before package phase that is at test phase, is there any way to run all junit after building a jar of project. Reason to run on build jar is to verify obfuscation of jar.
Upvotes: 2
Views: 3556
Reputation: 97557
Solution is to use the maven-failsafe-plugin which will in the integration test phase. You need to this to your pom file:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
You should following the conventions and follow the naming conventions of integration tests:
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
</includes>
Afterwards you can run those integration tests via:
mvn clean verify
If you like to run only unit tests:
mvn clean test
Upvotes: 5
Reputation: 2709
There are two phase of tests in maven, one is unit test, second is integration tests. So if You want, You should execute it in integration tests phase.
Upvotes: 0