Maven has to main plugins to run tests:
- maven-surefire-plugin: It is designed to run unit tests, it will run tests inside classes with “Test” in their class name.
- maven-failsafe-plugin: It is designed to run integration tests, it will run tests inside classes with “IT” in their class name.
In case that we just use maven-surefire-plugin we need to do add the folder that contains the integration tests, in other case it will run just the unit tests.
After this when we run:
- mvn verify → Unit and integration tests will be executed
- mvn integration-test → Unit and integration tests will be executed
- mvn test → Unit tests will be executed
- mvn package → Unit tests will be executed
- mvn install → Unit and integration tests will be executed.
In case that we want to use maven-failsafe-plugin we need to do this to include the integration tests:
After this when we run:
- mvn verify → Unit and integration tests will be executed.
- mvn integration-test → Unit and integration tests will be executed.
- mvn test → Unit tests will be executed.
- mvn package → Unit tests will be executed.
- mvn install → Unit and integration tests will be executed.
- mvn failsafe:integration-test → Integration tests will be executed and the build will not fail in case of a test does not pass.
- mvn failsafe:integration-test failsafe:verify → Integration tests will be executed and the build will fail in case of a test does not pass.