Search code examples
cucumber-jvm

How can we run something once before/after using CucumberJVM on forked JVM processes?


When we run cucumber tests on forked JVM processes, each test is isolated pretty much immediately, so if we try to use any sort of @before or @after it will run on every single jvm instance, and yes we could setup here, it will be executed on every process pointlessly...

How can we get in before the forked JVM processes and execute a single method even to validate the test run before proceeding etc?

The same should go for a run once after all tests on all JVM's have been executed.

Is there a simple solution for this?


Solution

  • Answer: I ended up writing a single individual test which validated the run and did all runOnce type code, telling surefire to run this test phase before the main one so the main test only continued when validation was a pass.

    other alternatives: maven plugin which I also wrote does the same kind of idea. other alternatives: get the JVM forked number from maven and set it as a system property, do some action(s) where the forked number == 1 for example and pause /sleep the other JVMs until the validation has been done, then continue (will require an external source to be updated, like a properties file with:

    canContinue=0

    to poll on each JVM until it is 1 to continue