adam bien's blog

A Natural Separation of JUnit Tests in Maven (3) 📎

Unit tests are fast, and integration tests are slow. Unit tests are also executed more frequently than integration tests. Tests ending with "*IT" are automatically executed by the failsafe plugin:

<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.8.1</version>
    <scope>test</scope>
</dependency>

Unit tests ending with "*Test" are executed by the standard surefire plugin
Now you can execute all unit tests with mvn install (or test) and integration tests with mvn failsafe:integration-tests. You will get immediate feedback after the execution of unit tests. The integration tests will be executed afterwards (in a separate Jenkins job).

[All x-ray unit tests are separated this way in separate Jenkins jobs. See page 131 "Build and Deployment" and page 136 "Continuous Integration and QA" in Real World Java EE Night Hacks--Dissecting the Business Tier.]