3

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

berimbolo
  • 3,319
  • 8
  • 43
  • 78
  • Take a look [here](http://khmarbaise.github.io/maui/it-example-container.html) – khmarbaise Sep 03 '15 at 08:40
  • ok that looks pretty similar to what I was thinking but does that work for 2 war files built as separate modules? – berimbolo Sep 03 '15 at 08:55
  • Is it a case of just adding more deployables? – berimbolo Sep 03 '15 at 08:57
  • You can use overlays and combine them to a single war file. Take a look [here](https://maven.apache.org/plugins/maven-war-plugin/overlays.html). – Koby Sep 03 '15 at 09:14
  • Would it be possible to do like your example and have an integration test module itself, and in this module add dependencies on both artefacts which will have been built by then, and then use multiple deployables and deploy both at the same time to tomcat via cargo? – berimbolo Sep 03 '15 at 09:17
  • I dont actually want a built war file with both compacted into one, I want two separate war files, as they will be deployed on production, deployed to tomcat and then tested from the front end down. – berimbolo Sep 03 '15 at 09:21
  • I think it might be possible, however I never tried it myself. This can be a good approach. – Koby Sep 03 '15 at 10:17
  • Just make two separate war modules which can be used by the it module...where you simply define them as dependencies. – khmarbaise Sep 03 '15 at 10:31
  • Thanks that is exactly what I am going to do, I already have 2 separate war modules being built anyway, your web page is very helpful as a basis for getting the integration tests up and running. – berimbolo Sep 03 '15 at 10:37
  • @khmarbaise I know this was some time ago but I was wondering if with your example you had managed to get code coverage with jacoco working from within the integration test module against a war file built from another module? – berimbolo May 24 '16 at 12:53

1 Answers1

4

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

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265