public final class RandomizedRunner extends Runner implements 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.
|
| 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(Filter filter)
Implement
Filterable because GUIs depend on it to run tests selectively. |
Description |
getDescription()
Return the current tree of test descriptions (filtered).
|
TraceFormatting |
getTraceFormatting()
Stack trace formatting utilities.
|
static String |
methodName(Description description)
Attempts to extract just the method name from parameterized notation.
|
void |
run(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 RandomizedRunner(Class<?> testClass) throws InitializationError
InitializationErrorpublic Description getDescription()
getDescription in interface DescribablegetDescription in class Runnerpublic void filter(Filter filter) throws NoTestsRemainException
Filterable because GUIs depend on it to run tests selectively.filter in interface FilterableNoTestsRemainExceptionpublic void run(RunNotifier notifier)
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(Description description)
Copyright © 2011-2013 Carrot Search s.c.. All Rights Reserved.