Search code examples
springspring-bootintegration-testingmaven-failsafe-plugin

Forked execution of SpringBootTest's with maven failsafe plugin - does it work out of the box?


Consider you have a Spring-Boot Application and within this application also a bunch of Integration-Tests, which are annotated with @SpringBootTest and run with the SpringRunner class. They are invoked by the maven failsafe plugin, which by default does not parallelise tests in any way. The tests all run fine without any issues.

What changes if you use failsafe's feature of forkCount - can you expect the test execution to work out of the box? Do you need to adjust some code? What do you need to look out for that could potentially not allow these integration tests to run in a forked, "parallel" environment via this plugin? From my understanding, the failsafe plugin will create forkCount-many JVMs and in each some of the integration tests are executed. That sounds like there is nothing to do, you don't need to make anything threadsafe, you don't need to make Singleton-beans into ThreadScoped beans or anything - as the process of having multiple JVM's should already create multiple of these beans. Sorry if the question appears weird, I tried researching this question but I could not find an answer.


Solution

  • From Maven doc:

    The parameter forkCount defines the maximum number of JVM processes

    This means that the tests will run in it's own process and therefore you will have separate Spring Boot instances. So you really don't have to care about thread safety.

    But you have to care about memory consumption.