End to end integration test for multiple spring boot applications under Maven
Just to follow-up and say what I ended up doing (which is continuing to work well):
- I created the following Maven profiles in my testing module: "default" to skip tests by default (we use jgitflow plugin so only want end-to-end tests run when explicitly requested), "standalone-e2e" for end-to-end tests not requiring external resources such as databases (aimed at developers wanting to do a full end-to-end test), and "integrated-e2e" for end-to-end tests using real databases etc (which can get triggered as part of CI). Spring profiles (activated by the corresponding Maven profile) control the configuration of the individual components.
- For standalone-e2e, relevant plugins such as activemq-maven-plugin, hsqldb-maven-plugin etc. launch (and later shut down) resources as part of the end-to-end test, running on ports reserved with build-helper-maven-plugin. The process-exec-maven-plugin is used to launch all the components to be tested in the pre-integration-test phase (as standard Spring Boot apps), and it automatically takes care of shutting them down in the post-integration-test phase. Spring configuration and specific Maven test dependencies take care of other resources such as a fake FTP server. After all resources and components are running, the test code itself then populates the database and file system as required and triggers flows (and waits for corresponding replies etc) using JMS.
- The integrated-e2e profile is almost identical but uses "real" external resources (in our case, Amazon SQS queues, MySQL database, etc) configured in the associated Spring properties.
- All files needed for and generated by the tests (e.g. data files, HSQLDB files, log files, etc) are created under the "target" build directory, so it's easy to inspect this area to see what happened during the test, and also allow "mvn clean" to clear out everything.
I hope that's useful - it was certainly refreshing to find that whatever I needed to do, a Maven plugin existed to take care of it!
Very nice question! I would by myself be interested what other people answer. I'll share my opinion.
In my understanding first of all you should know what exactly you want to test. Integration tests should work with an application of at least with a part of it and ensure that the component you've developed works properly in a semi-real environment. It seems like you've already done that.
Now, regarding system tests (I intentionally differentiate between integration and system tests). These should 'mimic' QA guys :) So, they treat a system as a black box. They can't invoke any internal APIs and run real flows. End-to-end tests IMO fall into this category.
In this case you would like to check them against the system deployed like in production, with the classpath like in production.
So I don't really believe in option 1 just like you.
Regarding the option 3 I'm not sure whether its a good solution as well. Even if you run your stuff with different application contexts (I don't know much Spring boot so I can't technically comment on it), in my understanding they will share the same classpath in runtime, so probably you're in risk to get clash among your thirdparties (although I know that spring boot defines a lot of versions of jars by itself, you know what I mean) especially when you upgrade only one module and probably change the dependencies. So you don't really know what exactly runs in memory when you run follow this approach.
So, for end-to-end tests, I would go with option 2. Regarding the synchronization, probably the option would be implementing some logic at the application level in conjunction with process state tracking at the level of operating system. One more point I would like to comment on is that end-to-end tests in general are still functional testing (they check the functional behavior of the system) so in general you shouldn't check system crashes there in each test. If you check the system crash for each flow, these tests will be too slow. Of course you can maintain one relatively small test suite to check corner cases as such.
Hope this helps