I am reading this tutorial on how to write integration tests using failsafe plugin
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).
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.