I'm trying to test a client/server application, and using Maven to handle the build/test/deploy. To test the application, I need to:
Steps 1,2,4 and 5 will use the maven-exec-plugin. Step 3 will use the maven-surefire-plugin.
The problem is that all 5 of these steps will occur in the 'test' phase. Maven allows plugins in to be executed in a specific order. the exec-plugin can be run multiple times by using multiple entries. The problem is that I need to use the surefire-plugin in the middle of the 4 exec-plugin executions.
Has anyone ever run into this before, or know how to structure the plugin's and execution's?
This is how I configured the exec and failsafe plugins. I'm using failsafe, rather than reconfiguring surefire, since surefire is still running other tests to be in the test phase. This will run steps 1 and 2 in the pre-integrationtest phase (multiple executions listed for the same phase will execute in the order given), run the test in the integration-test phase, and then clean up with steps 3 and 4 in the post-integrationtest phase.
(Note: I have echo commands in place of the real installation and cleanup commands)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
<configuration>
<forkMode>always</forkMode>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>step1</id>
<goals>
<goal>exec</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>foo</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>step2</id>
<goals>
<goal>exec</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>bar</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>step3</id>
<goals>
<goal>exec</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>baz</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>step4</id>
<goals>
<goal>exec</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
<executable>echo</executable>
<arguments>
<argument>woot</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
What you are trying to do sounds more like an integration test than a unit test. For this use case the default maven lifecycle has three phases related to integration testing:
pre-integration-test
: perform actions required before integration tests are executed. This may involve things such as setting up the required environment.integration-test
: process and deploy the package if necessary into an environment where integration tests can be run.post-integration-test
: perform actions required after integration tests have been executed. This may including cleaning up the environment.The surefire plugin usually executes in the test
phase, but can be reconfigured to execute in another phase. Your steps 1 + 2 can then be configured to execute in pre-integration-test
, while steps 4 + 5 have to execute in post-integration-test
.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- Skip execution in test phase and execute in integration-test phase instead -->
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With