What is the equivalent of reuseForks=false in Bazel?

Viewed 98

I want to set reuseForks=false in Bazel, so my tests don't reuse the same JVM process. How can I do that in Bazel?

According to https://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html

The parameter reuseForks is used to define whether to terminate the spawned process after one test class and to create a new process for the next test in line (reuseForks=false), or whether to reuse the processes to execute the next tests (reuseForks=true).

The default setting is forkCount=1/reuseForks=true, which means that maven-surefire-plugin creates one new JVM process to execute all tests in one Maven module.

forkCount=1/reuseForks=false executes each test class in its own JVM process, one after another. It creates the highest level of separation for the test execution, but it would probably also give you the longest execution time of all the available options. Consider it as a last resort.

2 Answers

By default Bazel doesn't reuse the same JVM process for tests, that functionality is hidden behind an experimental flag.

From the Bazel docs:

--[no]experimental_persistent_test_runner default: "false"

Allows running java_test targets locally within a persistent worker. To enable the persistent test runner one must run bazel test with the flags:--test_strategy=local --strategy=TestRunner=worker --experimental_persistent_test_runner

Related