UT = Unit Tests IT = Integration Tests. All my Integration test classes are annotated with @Category(IntegrationTest.class)
My goal is:
mvn clean install
=> runs UT and not IT
mvn clean install
-DskipTests=true => no tests are executed
mvn clean deploy
=> runs UT and not IT
mvn clean test
=> runs UT and not IT
mvn clean verify
=> runs UT and IT
mvn clean integration-test
=> runs IT and UT are not executed
mvn clean install deploy
=> runs UT and not IT
pom properties:
<junit.version>4.12</junit.version>
<surefire-plugin.version>2.18.1</surefire-plugin.version>
<failsafe-plugin.version>2.18.1</failsafe-plugin.version>
Compiler:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> <compilerArgument>-Xlint:all</compilerArgument> <showWarnings>true</showWarnings> <showDeprecation>true</showDeprecation> </configuration> </plugin>
Unit Tests:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${surefire-plugin.version}</version> <configuration> <excludedGroups>com.xpto.IntegrationTest</excludedGroups> </configuration> </plugin>
Integration Tests:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>${failsafe-plugin.version}</version> <configuration> <groups>com.xpto.IntegrationTest</groups> </configuration> <executions> <execution> <goals> <goal>integration-test</goal> </goals> <configuration> <includes> <include>**/*.class</include> </includes> </configuration> </execution> </executions> </plugin>
My results are:
mvn clean install
=> OK
mvn clean install
-DskipTests=true => OK
mvn clean deploy
=> runs UT and not IT
mvn clean test
=> OK
mvn clean verify
=> NOK ... only UT are executed but IT also needs to be executed
mvn clean integration-test
=> NOK ... UT are executed and should not and IT aren't executed but should be executed
mvn clean install deploy
=> OK
mvn integration-test
it runs through generate-sources, compile, compile-test, test, package, etc all the way up to and including integration-test. Your UT should be super-quick anyway, so why would you want to skip them? – Southwards*Test.java
and integration tests*IT.java
(see docs of maven-surefire-plugin/maven-failsafe-plugin). Furthermore if you do a thing like this :mvn clean install deploy
this does not make sense and didn't understand the maven build life cycle. If you domvn deploy
the install is part of the life cycle which in result means just usemvn deploy
. If a callmvn clean deploy
will run your UT but not IT's your configuration is wrong. – Arielariela