public class Context extends Object
Typically, you should not interact with this class directly, preferring to use an integration with your particular testing framework. If that integration is not available, or if you are writing your own, you will need to manage the context manually.
The context is backed by state stored in a thread local and therefore any generators must be initialized on the
same thread where Context.init is executed.
Example usage:
public void executeFuzzyTest() {
// Initialize the testing context. This applies to all generators
// created on this thread.
Context.init();
try {
do {
// Execute your test code here.
executeSingleTestIteration();
} while(Context.next());
}
catch(AssertionError | Exception e) {
// Handle test failures
// You can use Context.report() or Context.reportTo(StringBuilder)
// to get a sense of the inputs that caused the test failure.
}
finally {
// Clean up for the next test
Context.cleanUp();
}
}
| Modifier and Type | Method and Description |
|---|---|
static void |
cleanUp()
Marks the completion of a single test execution and all iterations.
|
static void |
init(CaseCompositionMode caseCompositionMode,
long randomSeed)
Initializes the context in preparation for running a single test (the context should be initialized for each
test individually).
|
static boolean |
next()
Marks the termination of a single iteration of the test being executed, and returns
true if more
iterations are necessary to execute all test cases. |
static String |
report()
Produces a human-readable report of the context's status, in American English.
|
static void |
reportTo(StringBuilder sb)
Produces a human-readable report of the context's status, in American English.
|
static Map<Generator,Object> |
valuesForCurrentIteration()
Returns a map of the objects that have been chosen for the various generators created by the current test
iteration.
|
public static void init(CaseCompositionMode caseCompositionMode, long randomSeed)
caseCompositionMode - the algorithm Context should use to build permutations of the test variables.randomSeed - the seed to use for all randomized calls for this test; setting the seed consistently makes the
randomization deterministic across different test passes.public static boolean next()
true if more
iterations are necessary to execute all test cases.public static void cleanUp()
remove must be called before
init can be called for the next test.public static Map<Generator,Object> valuesForCurrentIteration()
public static String report()
public static void reportTo(StringBuilder sb)
Copyright © 2017 Redfin. All rights reserved.