Search code examples
javamavenjunit4maven-failsafe-plugin

Where should the integration tests be stored when using the maven-failsafe-plugin?


Do I have to place my integration tests under src/test with the rest of my unit tests and just distinguish them by a pattern such as *Integr*Test, *ITTest, or can they be in src/it (as is the case when developing Maven plugins and using the maven-invoker-plugin)?

I'm asking this because, to me it looks not clean enough if both unit and integration tests are in the same place, (even if they were to be controlled via a Maven profile).


Solution

  • First maven-fails-plugin runs by default in another life cycle phase (integration-test) as maven-surefire-plugin (test) does. Furthermore you can configura maven-failsafe-plugin to run verify goal at the post-integration-test test phase if you like to check if integration tests have failed. This can be freely configured.

    There is one question coming into my mind. You have 10 modules and now you would like to have integration tests? To which module do they belong? So best is to have a separate module cause they belong to none of the 10 modules.

    Apart from that maven-surefire-plugin is already configured in default life cycle. Yes a supplemental goal would be an idea, but it would confuse user to use the same plugins in different relationships. So separation of concerns is important here. Apart from the whole default configurations...Those plugins share a larger code base but there are differences...

    Also what has already been mentioned by Tunaki is pre-integration-test, for setup things like servers etc. integration-test and things like shutting down services/servers in post-integration-test phase. This will never happen in unit tests.

    Using a separate module makes it usually simpler to setup the IT's which means having different dependencies (classpath) than for the unit tests. For example things like Arquillian.org which is never using in unit tests. This can't be handled in a single module...also a good things is separation of concerns here..

    Furthermore integration tests could not be parallized by default whereas unit tests can be by definition otherwise they not unit tests.

    So what about folder layout? In the integration test module you can simply use the src/test/java folder which means you don't need supplemental configuration etc. (for example via build-helper-maven-plugin etc.) which makes it easier and follows more the convention over configuration paradigm.

    And not to forget you can better control what is running in your build (CI)..

    And another important hint. Usually integration tests are often related to infrastructure so it might sometimes useful to ignore failures there which can simply handle by using check goal of maven-failsafe-plugin....

    An example for an IT module can be found here.