public class ConcurrentTestRunner
extends org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
ParallelExecutor as a parameter, which the
test can use to invoke code in parallel.
This test run will try to exercise the test method to flush out any concurrent bugs in the
parallel execution.
All test logic and state *must* be encapsulated in the individual test methods. This is because
the concurrency testing logic may need to invoke the test body multiple times, possibly in
parallel.
No guarantees are currently made about logic in methods annotated with @Before, @BeforeClass or
about the behavior of Rule for concurrent tests.
Example
@RunWith(ConcurrentTestRunner.class)
public void MyTest {
@Test
public void someTestMethod(ParallelExecutor executor) {
AtomicInteger atomicInteger = new AtomicInteger();
executor.inParallel(() -> atomicInteger.incrementAndGet());
executor.inParallel(() -> atomicInteger.incrementAndGet());
executor.execute();
assertEquals(2, atomicInteger.get());
}
}
ConcurrentTestRunner currently executes tests using the LoopRunner which will run the
test many times.| Constructor and Description |
|---|
ConcurrentTestRunner(java.lang.Class testClass) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
collectInitializationErrors(java.util.List<java.lang.Throwable> errors) |
protected org.junit.runner.Description |
describeChild(org.junit.runners.model.FrameworkMethod child) |
protected java.util.List<org.junit.runners.model.FrameworkMethod> |
getChildren() |
protected void |
runChild(org.junit.runners.model.FrameworkMethod child,
org.junit.runner.notification.RunNotifier notifier) |
public ConcurrentTestRunner(java.lang.Class testClass)
throws org.junit.runners.model.InitializationError
org.junit.runners.model.InitializationErrorprotected java.util.List<org.junit.runners.model.FrameworkMethod> getChildren()
getChildren in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>protected void collectInitializationErrors(java.util.List<java.lang.Throwable> errors)
collectInitializationErrors in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>protected org.junit.runner.Description describeChild(org.junit.runners.model.FrameworkMethod child)
describeChild in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>protected void runChild(org.junit.runners.model.FrameworkMethod child,
org.junit.runner.notification.RunNotifier notifier)
runChild in class org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>