Monday, August 24, 2009

Maven gotcha: "post-integration-test" phase

In Maven, "post-integration-test" phase can be used to do test clean up, for example, to shut down Cargo after the tests finished.

If you run "maven install" then the phases would be in this order:

pre-integration-test: start Cargo (web server)
integration-test: start tests
post-integratino-test: stop Cargo

However, if you just run "maven integration-test" to run the tests directly, "post-integration-test" phase is never called, which might lead to your cleanup process not being run.

So the workaround is to bind your clean up tasks to "integration-test" itself which will be run right after the tests run during that phase.

1 comment:

Jean Hominal said...

I see two problems with your workaround:
* How can you guarantee that the tests will be run before cleanup? In other terms, how does Maven order the tasks it does in a single phase?
* If one of your tests fails, won't the build fail at the integration-test phase and cause the remaining tasks (such as cleanup) to not be run?

As a solution to all these problems I use the Failsafe plugin my integration tests, that solves all the aforementioned problems (one runs integration tests not with the "integration-test" phase but with the "verify" phase)