berimbolo
berimbolo

Reputation: 3859

Integration testing in maven multi module project

I have a multi module project and I now want to add integration tests to it, I want to use the cargo plugin to start tomcat and deploy my artefacts there and then test end to end using selenium.

I have looked through the maven console output for my current build and surefire unit tests and then read the maven docs for the failsafe plugin this looks ok but it looks like the life cycle is for each module as the logs indicate that a module is tested then built before moving onto the next module.

Am I understanding this correctly?

As my app consists of a war that is the front end only which then connects to the backend api app which is a rest api that connects to the database I need to have both war files deployed to cargo in the integration test phase at the same time.

Does anybody know how to do this or can point me to a tutorial that does integration tests between multiple war files in tomcat?

Thanks

Upvotes: 3

Views: 3262

Answers (1)

Paul Sweatte
Paul Sweatte

Reputation: 24637

The Maven plugin lifecycle is as follows:

  1. validate pom.xml
    • initialize
  2. generate-sources
    • process-sources
  3. generate-resources
    • process-resources
  4. compile
    • process-classes
  5. generate-test-sources
    • process-test-sources
  6. generate-test-resources
    • process-test-resources
  7. test-compile
    • process-test-classes
  8. test
  9. prepare-package
    • package
  10. pre-integration-test
  11. integration-test
  12. post-integration-test
  13. verify
  14. install
  15. deploy

org.mockserver can be used for the aforementioned purpose of testing multiple war files.

To run MockServer as part of your build add the following plugin to your pom.xml:

<plugin>
    <groupId>org.mock-server</groupId>
    <artifactId>mockserver-maven-plugin</artifactId>
    <version>3.10.7</version>
    <configuration>
        <serverPort>1080</serverPort>
        <proxyPort>1090</proxyPort>
        <logLevel>DEBUG</logLevel>
        <initializationClass>org.mockserver.maven.ExampleInitializationClass</initializationClass>
    </configuration>
    <executions>
        <execution>
            <id>process-test-classes</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>verify</id>
            <phase>verify</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>

This will start MockServer during the process-test-classes phase and will stop MockServer during the verify phase. For more details about Maven build phases see: Introduction to the Build Lifecycle.

This ensures that any integration tests you run during the test or integration-test phases can use MockServer on the port specified.

A full example demonstrates MVC integration.

Maven Lifecycle Phases Diagram

Plugin goals can be attached to a lifecycle phase References

Upvotes: 4

Related Questions