Maven: Running Integration Tests from Test Artifacts
Perhaps you know this situation:
Your project has a bunch of integration tests you use for judging the quality of your project deployment. Now a product aggregates many projects, including yours, and wants to run the same integration tests with the complete system (also known as system tests). Of course it would be best to deliver the tests along with your project artifacts. But how?
If this is the question you are asking yourself then I might offer you one possible solution which I found after some research. To get a quick impression on what I achieved you might want to directly clone the GitHub repository with the proof-of-concept code.
The example I created consists of three Maven sub-modules:
Contains the project you want to test. Very simple here.
Contains the tests which you want to run as integration test and deploy them in order to do system tests with them.
Contains the driver for the system tests. Typically this will be a very different workspace.
The first time you address this task you will find a bunch of posts out there all dealing with the same problem:
While there is a way to bundle test artifacts using the maven-jar-plugin’s Mojo test-jar there is no obvious way in executing them in a different context. The issue SUREFIRE-569 exists since some years concerning this issue which affects both, the maven-failsafe-plugin as well as the maven-surefire-plugin: You cannot execute tests which are located in your classpath.
The suggested workaround is to use the maven-dependency-plugin to extract the test artifacts. Not really nice fiddling around with the build process. But what could be done instead?
The solution you will find in the GitHub repository uses a different way. For accessing the tests a Suite file is generated and for adjusting the configuration Spring context configuration is used. Being the integrating project you now only need to:
- Create a Suite-File as hook into the test-artifacts.
- Create a Context-File to override the environment-configuration so that it matches the integration scenario.
- Add a dependency to the test artifacts in your POM.
The charming result is that as project team you can pre-define the tests to run in the system tests which might be a subset of their own tests they are running. And as system tester you can easily plug together the tests for the different modules you are integrating.
Do you like the solution? Do you have different ideas/solutions on this topic? Would be great to get your comments on this.