Reactor Strategies

A reactor strategy defines a factory for creating reactors. The reactor strategy determines whether or not the test container will be stopped and restarted between tests.

The reactor strategy is defined by an annotation on the test class.

@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class ExplodedReferenceTest
{
}

PerMethod

With the per method strategy, the test container is started and stopped before and after each individual test method.

This strategy is only supported in OSGi mode. This strategy is synonymous with AllConfinedStagedReactorFactory of Pax Exam 2.x which is still supported but now deprecated.

PerMethod is the default strategy in OSGi mode.

PerClass

With the per class strategy, the test container is started and stopped before and after running all tests of a given test class. Thus, subsequent test methods are not completely isolated from any side effects of previous methods of the same test class.

This strategy is only supported in OSGi and CDI modes. This strategy is synonymous with EagerSingleStagedReactorFactory of Pax Exam 2.x which is still supported but now deprecated.

PerSuite

With the per suite strategy, the test container is started once before running all test classes of the current probe and is stopped after the entire suite has run. This strategy minimizes the container startup and shutdown overhead at the price of no isolation and potential side effects between test classes or methods.

This strategy is only supported in Java EE, CDI and Web modes.

PerSuite is the default strategy in these modes.

For Pax Exam, a suite is the set of all test classes of the current run. This does not in general coincide with the concept of a suite in JUnit or TestNG.

The contents of a suite is usually determined by an external runner like Maven Surefire or Eclipse. E.g. when selecting Run As | JUnit Test from the context menu of a Java package in Eclipse, then the suite will contain all classes from the given package annotated by @RunWith(PaxExam.class).

Since JUnit does not fire any before suite or after suite events, the reactor is started lazily before the first test method is executed and is stopped using a VM shutdown hook.