I have a maven2 multi-module project and in each of my child modules I have JUnit tests that are named Test.java
and Integration.java
for unit tests and integration tests respectively. When I execute:
mvn test
all of the JUnit tests *Test.java
within the child modules are executed. When I execute
mvn test -Dtest=**/*Integration
none of the Integration.java
tests get execute within the child modules.
These seem like the exact same command to me but the one with the -Dtest=/*Integration** does not work it displays 0 tests being run at the parent level, which there are not any tests
Another way of running integration tests with Maven is to make use of the profile feature:
Running 'mvn clean install' will run the default build. As specified above integration tests will be ignored. Running 'mvn clean install -P integration-tests' will include the integration tests (I also ignore my staging integration tests). Furthermore, I have a CI server that runs my integration tests every night and for that I issue the command 'mvn test -P integration-tests'.
You can follow the maven documentation to run the unit tests with the build and run the integration tests separately.
This will allow you to run with all integration tests disabled by default. To run them, you use this command:
You can split them very easily using JUnit categories and Maven.
This is shown very, very briefly below by splitting unit and integration tests.
Define A Marker Interface
The first step in grouping a test using categories is to create a marker interface.This interface will be used to mark all of the tests that you want to be run as integration tests.
Mark your test classes
Add the category annotation to the top of your test class. It takes the name of your new interface.
Configure Maven Unit Tests
The beauty of this solution is that nothing really changes for the unit test side of things.We simply add some configuration to the maven surefire plugin to make it to ignore any integration tests.
When you do a mvn clean test only your unmarked unit tests will run.
Configure Maven Integration Tests
Again the configuration for this is very simple.We use the standard failsafe plugin and configure it to only run the integration tests.
The configuration uses a standard execution goal to run the failsafe plugin during the integration-test phase of the build.
You can now do a mvn clean install
This time as well as the unit tests running, the integration tests are run during the integration-test phase.
You can set up Maven's Surefire to run unit tests and integration tests separately. In the standard unit test phase you run everything that does not pattern match an integration test. You then create a second test phase that runs just the integration tests.
Here is an example:
You should try using maven failsafe plugin. You can tell it to include a certain set of tests.
By default, Maven only runs tests that have Test somewhere in the class name.
Rename to IntegrationTest and it'll probably work.
Alternatively you can change the Maven config to include that file but it's probably easier and better just to name your tests SomethingTest.
From Inclusions and Exclusions of Tests: