You could apply the following configuration:
- Configure the
maven-surefire-plugin
or the maven-failsafe-plugin
(better for integration tests, which sounds more appropriate in this use case) to execute the first set of tests via its include/exclude mechanism, as first execution of this plugin
- Configure the
maven-surefire-plugin
(or the maven-failsafe-plugin
) to execute a sample test case whose only purpose would be to sleep for a determined (or configurable) time, again via include/exclude mechanism, as second execution of this plugin (Maven will respect execution order as per pom.xml
file declaration)
- Configure the
maven-surefire-plugin
(or the maven-failsafe-plugin
) to execute the second set of tests (or a single check test, in this use case), again via include/exclude, as third execution (which will then be executed as last one).
Using the same plugin with several executions for the same phase will ensure you the declaration order will be followed during Maven execution.
Below a sample snippet of the approach above:
<profile>
<id>check-test</id>
<build>
<properties>
<sleep.time>2000</sleep.time>
</properties>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>first-execution</id>
<phase>test</phase>
<configuration>
<includes>
<include>*FirstTestsSample.java</include>
</includes>
</configuration>
</execution>
<execution>
<id>second-execution</id>
<phase>test</phase>
<configuration>
<includes>
<include>SleepTest.java</include>
</includes>
<systemPropertyVariables>
<sleepParam>${sleep.time}</sleepParam>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>third-execution</id>
<phase>test</phase>
<configuration>
<includes>
<include>CheckTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Note, I wrapped everything in a Maven profile for cleanness since you probably don't want this behavior as part of your default build but only executed on demand (or as part of a CI job).
If you need to configure the sleeping time, you could then configure the concerned configuration
section of each execution
via the systemPropertyVariables
option.
You can then invoke your build as following:
mvn clean verify -Pcheck-test -Dsleep.time=3000
Where the -P
is enabling the profile by its id and we are also overriding the default value of the sleep.time
property via command line, passed then as value of the sleepParam
system variable which can be fetched from Java code via a System.gerProperty("sleepParam")
call.
Also note, the maven-failsafe-plugin
may better suit your scenario since it better handles post-execution of integration/acceptance tests, as also described in its official page, even though your use case may still be served by the `maven-surefire-plugin'.