Reputation: 2160
In my code I have 2 types of tests: fast unit tests and slow performance tests. I am trying to ensure that the performance tests are never run unless the user explicitly wants to run them (e.g. using the right test suite or maven build profile) because this kicks of a remote process that is computationally-intensive on a grid.
I understand how to create build profiles that exclude (or include) specific tests using maven-surefire-plugin as explained on this site. The problem I have, however, is that I have not found a way to exclude tests from the default run while still providing the option to run the test when needed. By default run I mean:
In both cases above it runs all the unit tests (include the slow tests I hope to exclude by default). The same thing happens if there is a typo in the build profile I try to run.
Is there a way I can excluse performance tests from the default run without having to move them to a separate maven module?
Upvotes: 7
Views: 4301
Reputation: 611
The native Junit case of your question can AFAIK only be kind of solved by keeping different tests in different source folders (or packages) and go to the run configuration at "Run all tests in ..." and limit the tests to run according to the specific source folder (or package).
I know of no versatile way to make that in a general way, but it's not too burdensome to make a new run configuration set per project (by duplicating an existing one) and remove those that are no longer relevant.
Upvotes: 0
Reputation: 31
What we have done in our projects is to mark the slow unit tests with a special marker interface.
@Cathegory(SlowTest.class)
annotation and add them to the failsafe plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<groups>com.whatever.SlowTest</groups>
</configuration>
<executions>
<execution>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
</configuration>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
If you don't want to execute them: use the maven option -DskipITs. This will skip them.
Upvotes: 2
Reputation: 10833
Using profiles
you can make one active by default that excludes your slow tests and use another one to run all tests.
You have to specify those tags in your fastTestOnly
profile :
<profiles>
<profile>
<id>fastTestOnly</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
...
</profile>
</profiles>
This way, when you run a simple mvn install
only the profile picked is fastTestOnly
.
Upvotes: 1