public final class RandomizedRunner
extends org.junit.runner.Runner
implements org.junit.runner.manipulation.Filterable
Runner
implementation for running randomized test cases with
predictable and repeatable randomness.
Supports the following JUnit4 features:
BeforeClass
-annotated methods (before all tests of a class/superclass),Before
-annotated methods (before each test),Test
-annotated methods,After
-annotated methods (after each test),AfterClass
-annotated methods (after all tests of a class/superclass),Rule
-annotated fields implementing MethodRule
and TestRule
.Contracts:
BeforeClass
, Before
methods declared in superclasses are called before methods declared in subclasses,AfterClass
, After
methods declared in superclasses are called after methods declared in subclasses,BeforeClass
, Before
, AfterClass
, After
methods declared within the same class are called in randomized order
derived from the master seed (repeatable with the same seed),Deviations from "standard" JUnit:
ThreadGroup
active counts and is sometimes problematic (many classes
in the standard library leave active threads behind without waiting for them to terminate).
One can use the ThreadLeaks
annotation to control how aggressive the detection
strategy is and if it fails the test or not.RandomizedTest
,
ThreadLeaks
,
Validators
,
Listeners
,
RandomizedContext
,
TestMethodProviders
Modifier and Type | Field and Description |
---|---|
static String |
AUGMENTED_SEED_PACKAGE
Fake package of a stack trace entry inserted into exceptions thrown by
test methods.
|
static int |
DEFAULT_ITERATIONS
The default number of test repeat iterations.
|
static int |
DEFAULT_KILLATTEMPTS
The default number of first interrupts, then Thread.stop attempts.
|
static int |
DEFAULT_KILLWAIT
Time in between interrupt retries or stop retries.
|
static int |
DEFAULT_TIMEOUT
Default timeout for a single test case.
|
static int |
DEFAULT_TIMEOUT_SUITE
Default timeout for an entire suite.
|
com.carrotsearch.randomizedtesting.GroupEvaluator |
groupEvaluator |
Constructor and Description |
---|
RandomizedRunner(Class<?> testClass)
Creates a new runner for the given class.
|
Modifier and Type | Method and Description |
---|---|
ArrayList<Object[]> |
collectFactoryParameters()
Collect parameters from factory methods.
|
void |
filter(org.junit.runner.manipulation.Filter filter)
Implement
Filterable because GUIs depend on it to run tests selectively. |
org.junit.runner.Description |
getDescription()
Return the current tree of test descriptions (filtered).
|
TraceFormatting |
getTraceFormatting()
Stack trace formatting utilities.
|
static boolean |
hasZombieThreads()
Returns true if any previous (or current) suite marked with
ThreadLeakZombies.Consequence#IGNORE_REMAINING_TESTS has
left zombie threads. |
static String |
methodName(org.junit.runner.Description description)
Attempts to extract just the method name from parameterized notation.
|
void |
run(org.junit.runner.notification.RunNotifier notifier)
Runs all tests and hooks.
|
static String |
seedFromThrowable(Throwable t)
RandomizedRunner augments stack traces of test methods that ended in an exception
and inserts a fake entry starting with AUGMENTED_SEED_PACKAGE . |
public static final String AUGMENTED_SEED_PACKAGE
public static final int DEFAULT_TIMEOUT
SysGlobals.SYSPROP_TIMEOUT
or an annotation Timeout
if you need to set
timeouts or expect some test cases may hang. This will slightly slow down
the tests because each test case is executed in a forked thread.public static final int DEFAULT_TIMEOUT_SUITE
SysGlobals.SYSPROP_TIMEOUT_SUITE
or an annotation TimeoutSuite
if you need to set
timeouts or expect some tests (hooks) may hang.public static final int DEFAULT_KILLATTEMPTS
public static final int DEFAULT_KILLWAIT
public static final int DEFAULT_ITERATIONS
public com.carrotsearch.randomizedtesting.GroupEvaluator groupEvaluator
public RandomizedRunner(Class<?> testClass) throws org.junit.runners.model.InitializationError
org.junit.runners.model.InitializationError
public org.junit.runner.Description getDescription()
getDescription
in interface org.junit.runner.Describable
getDescription
in class org.junit.runner.Runner
public void filter(org.junit.runner.manipulation.Filter filter) throws org.junit.runner.manipulation.NoTestsRemainException
Filterable
because GUIs depend on it to run tests selectively.filter
in interface org.junit.runner.manipulation.Filterable
org.junit.runner.manipulation.NoTestsRemainException
public void run(org.junit.runner.notification.RunNotifier notifier)
run
in class org.junit.runner.Runner
public ArrayList<Object[]> collectFactoryParameters()
public TraceFormatting getTraceFormatting()
public static String seedFromThrowable(Throwable t)
RandomizedRunner
augments stack traces of test methods that ended in an exception
and inserts a fake entry starting with AUGMENTED_SEED_PACKAGE
.public static String methodName(org.junit.runner.Description description)
public static boolean hasZombieThreads()
ThreadLeakZombies.Consequence#IGNORE_REMAINING_TESTS
has
left zombie threads.Copyright © 2011–2015 Carrot Search s.c.. All rights reserved.