1

I am reading this tutorial on how to write integration tests using failsafe plugin

https://www.javacodegeeks.com/2015/01/separating-integration-tests-from-unit-tests-using-maven-failsafe-junit-category.html

its good. but I need to write test setup hooks. in these hooks I will provision docker containers. I also need to write tear-down hooks where the containers will be shutdown.

I found this code where there is logic for create, start of container, and shutdown of container.

https://github.com/wouterd/hippo-docker/blob/master/myhippoproject/integrationtests/pom.xml

but I am not sure how will the test run and how will these goals defined in the XML get called in the right order for the integration test to run.

Basically, I need first the build-images to get called, then start-containers, then the test has to be run and finally stop-and-cleanup.

Can someone help me in connecting these dots. (these may be obvious).

Knows Not Much
  • 30,395
  • 60
  • 197
  • 373

1 Answers1

1

You need to have an understanding of the Maven Lifecycle. This defines the "path" that maven will execute various phasese of the a build. If you read through the Lifecycle Reference you will see the various phases listed in order of execution.

Each of these phases can be attached to by different plugins. The particular docker maven plugin used in hippo-docker defines the different "goals" (e.g. start-containers) to be, by default, attached to the pre-integration-test lifecycle phase.

Plugins will be executed in a particular phase in the order they were declared within the pom.xml. If you have plugin-a bound to phase-x and then declare plugin-b bound to phase-x the order will be plugin-a then plugin-b.

In the case of integration tests, maven-failsafe-plugin ensures that any failures within the unit test execution are trapped and recorded so that the post-integration-test phase can run. Typically you would run "mvn verify" to ensure that you execute through pre-integration-test, integration-test, post-integration-test.

Dave G
  • 9,639
  • 36
  • 41
  • 1
    one quick clarification would be that in the code here https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference They very explicitly specify the "phase" when they declare their goals. but the hippo code above just specifies the goals but does not say which phase does the goal tie into. So someone who is reading the hippo code.... how will they come to know that "stop-and-cleanup" ties into post-integration? – Knows Not Much Apr 14 '16 at 06:28
  • 1
    Good point - it was kind of late last night - I did go into the docker-maven-plugin source code and examined the "Mojos" defined to handle those tasks and read the annotations. – Dave G Apr 14 '16 at 10:49