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

Is it necessary to conduct integration tests in src/test with other unit tests and just distinguish them by a template, for example *Integr*Test , *ITTest , or can they be in src/it (as is the case with Maven plugins and using maven-invoker-plugin )?

I ask about this because for me it doesn’t seem clean enough if unit tests and integration tests are in the same place (even if they should be controlled through the Maven profile).

+5
source share
2 answers

First, the maven-fail-plugin starts by default in a different phase of the life cycle (integration test), as the maven-surefire-plugin (test) does. In addition, you can configure the maven-fail-safe plugin to run the verify target during the post-integration-test testing phase if you want to check if the integration tests have completed. It can be freely configured.

One question comes into my mind. You have 10 modules, and now you want to carry out integration tests? Which module do they belong to? It is best to have a separate module because they do not belong to any of the 10 modules.

In addition, the maven-surefire plugin is already configured in the default life cycle. Yes, an additional goal would be an idea, but it would confuse the user to use the same plugins in different ways. Therefore, separation of concerns is important here. In addition to standard default configurations ... These plugins have a large code base, but there are differences ...

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

Using a separate module simplifies IT configuration, which means there are different dependencies (classpath) than for unit tests. For example, things like Arquillian.org that are never used in unit tests. This cannot be handled in one module ... also the good things are the separation of concerns here.

In addition, by default, integration tests cannot be paralyzed, while unit tests can be by definition, otherwise they will not test units.

What about the location of the folders? In the integration test module, you can simply use the src/test/java folder, which means you don't need additional configuration, etc. (For example, through build-helper-maven-plugin, etc.), which simplifies it and requires more coordination on the configuration of the paradigm.

And don't forget that you can better control what works in your assembly (CI) ..

And one more important hint. Usually integration tests are often related to the infrastructure, so it is sometimes useful to ignore errors there that can simply be handled by the check target of the maven-fail-safe-plugin ....

An example for an IT module can be found here .

+5
source

You are correct that src/it intended to be used to test plugin integration. This is indicated in the standard catalog layout .

maven-failsafe-plugin by default look for your integration tests inside ${project.build.testSourceDirectory} , which matches the maven-surefire-plugin for unit tests. By default, this corresponds to src/test/java . Integration tests are performed as follows: naming convention :

 <includes> <include>**/IT*.java</include> <include>**/*IT.java</include> <include>**/*ITCase.java</include> </includes> 

which differs from the naming convention for unit tests:

 <includes> <include>**/Test*.java</include> <include>**/*Test.java</include> <include>**/*TestCase.java</include> </includes> 

Therefore, while they will be in the same source folder ( src/test/java ), the difference in names clearly distinguishes them. In addition, this is the default setting, so no additional configuration is required.

However, you may have other options:

  • Place the integration tests in a different source folder. This will require some tweaking to make it work: you will need to use the build-helper-maven-plugin:add-test-source target to add the user folder as the test source folder.
  • Use a different module (if you have a multi-module Maven project) that will contain integration tests.
+8
source

All Articles