Second, we have to create an execution that adds the source directory of our integration tests (src/integration-test/java) into our Maven build. This execution must invoke the add-test-source goal of the Build Helper Maven Plugin when the generate-test-sources phase of the Maven default lifecycle is invoked.

After we have created this execution, the configuration of the Build Helper Maven Plugin looks as follows:

Third, we have to create an execution that adds the resource directory of our integration tests (src/integration-test/resources) into our Maven build. This execution must invoke the add-test-resource goal of the Build Helper Maven Plugin when the generate-test-resources phase of the Maven default lifecycle is invoked.

After we have created this execution, the configuration of the Build Helper Maven Plugin looks as follows:

Next, we have to ensure that our unit tests are run only when the dev Maven profile is active.

Configuring Maven to Skip Our Unit Tests

The Maven Surefire Plugin doesn’t run unit tests when the value of its skipTests configuration option is true. Because we want to run our unit tests only when the dev profile is active, we have to configure Maven to read the value of this configuration option from the value of the skip.unit.tests property.

After we have done this, the configuration of the Maven Surefire Plugin looks as follows:

Before we can configure Maven to run our integration tests, we have to write one integration test.

Writing a Simple Integration Test

The SampleIntegrationTest class contains one integration test that writes the string: ‘The category: IntegrationTest’ to System.out. Because we want to configure the category of this test class, we have to annotate it with the @Category annotation.

First, we have ensure that both integration-test and verify goals of this plugin are run. The integration-test goal runs our integration tests and the verify goal checks the results of our integration tests and fails the build if our integration tests failed.

After we have configured these goals, the configuration of the Maven Failsafe Plugin looks as follows:

Third, we have to ensure that Maven Failsafe Plugins runs all tests that belong to the IntegrationTest category. We can specify the used category by setting the fully qualified class name of our category interface as the value of the groups configuration option.

After we have configured the used category, the configuration of the Maven Failsafe Plugin looks as follows:

Fourth, we have to ensure that the Maven Failsafe Plugin runs integration tests only if the integration-test Maven profile is active. The Maven Failsafe Plugin doesn’t run integration tests when the value of its skipTests configuration option is true.

Because we want to run our integration tests only if the integration-test profile is active, we have to configure Maven to read the value of this configuration option from the value of the skip.integration.tests property.

After we have done this, the configuration of the Maven Failsafe Plugin looks as follows: