I have a number of feature files in my cucumber scenario test suite.
I run the tests by launching Cucumber using the CLI.
These are the steps which occur when the test process is running:
- We create a
static
instance of a class which manages the lifecycle of testcontainers for my cucumber tests.- This currently involves three containers: (i) Postgres DB (with our schema applied), (ii) Axon Server (event store), (iii) a separate application container.
- We use spring's new
@DynamicPropertySource
to set the values of our data source, event store, etc. so that the cucumber process can connect to the containers.
@Before
each scenario we perform some clean up on the testcontainers.- This is so that each scenario has a clean slate.
- It involves truncating data in tables (postgres container), resetting all events in our event store (Axon Server container), and some other work for our application (resetting relevant tracking event processors), etc.
Although the tests pass fine, the problem is by default it takes far too long for the test suite to run. So I am looking for a way to increase parallelism to speed it up.
- Adding the arguments
--threads <n>
will not work because thestatic
containers will be in contention (and I have tried this and as expected it fails).
The way I see it there is are different options for parallelism which would work:
- Each scenario launches its own spring application context (essentially forking a JVM), gets its own containers deployed and runs tests that way.
- Each feature file launches its own spring application context (essetially forking a JVM), gets its own containers deployed and runs each scenario serially (as it would normally).
I think in an ideal world we would go for 1 (see *). But this would require a machine with a lot of memory and CPUs (which I do not have access to). And so option 2 would probably make the most sense for me.
My questions are:
- is it possible to configure cucumber to fork JVMs which run assigned feature files (which matches option 2 above?)
- what is the best way to parallelise this situation (with testcontainers)?
* Having each scenario deployed and tested independently agrees with the cucumber docs which state: "Each scenario should be independent; you should be able to run them in any order or in parallel without one scenario interfering with another. Each scenario should test exactly one thing so that when it fails, it fails for a clear reason. This means you wouldn’t reuse one scenario inside another scenario."