public class RandomBug extends Object
Principle is to increase consistency on tests which have a random behavior. Such test is a headache because:
Compared to the @Ignore
JUnit annotation, the advantage is to provide different behaviors for different use
cases. The wanted behavior depending on whereas:
import org.nuxeo.runtime.test.runner.FeaturesRunner; import org.nuxeo.runtime.test.RandomBugRule; @RunWith(FeaturesRunner.class) public class TestSample { public static final String NXP99999 = "Some comment or description"; @Test @RandomBug.Repeat(issue = NXP99999, onFailure=5, onSuccess=50) public void testWhichFailsSometimes() throws Exception { assertTrue(java.lang.Math.random() > 0.2); } }
In the above example, the test fails sometimes. With the RandomBug.Repeat
annotation, it will be repeated in
case of failure up to 5 times until success. This is the default RandomBug.Mode.RELAX
mode. In order to reproduce the
bug, use the RandomBug.Mode.STRICT
mode. It will be repeated in case of success up to 50 times until failure. In
RandomBug.Mode.BYPASS
mode, the test is ignored.
You may also repeat a whole suite in the same way by annotating the class itself. You may want also want to skip some
tests, then you can annotate them and set RandomBug.Repeat.bypass()
to true.
RandomBug.Mode
Modifier and Type | Class and Description |
---|---|
protected class |
RandomBug.Bypass |
static class |
RandomBug.Feature |
static class |
RandomBug.Mode
BYPASS: the test is ignored.
|
static interface |
RandomBug.Repeat
Repeat condition based on
|
protected class |
RandomBug.RepeatOnFailure |
protected class |
RandomBug.RepeatOnSuccess |
class |
RandomBug.RepeatRule |
protected class |
RandomBug.RepeatStatement |
Modifier and Type | Field and Description |
---|---|
RandomBug.Mode |
DEFAULT
The default mode if
MODE_PROPERTY is not set. |
static String |
MODE_PROPERTY |
protected static RandomBug |
self |
Constructor and Description |
---|
RandomBug() |
Modifier and Type | Method and Description |
---|---|
protected RandomBug.Mode |
fetchMode() |
protected RandomBug.RepeatRule |
onMethod() |
protected RandomBug.RepeatStatement |
onRepeat(RandomBug.Repeat someParams,
org.junit.runner.notification.RunNotifier aNotifier,
org.junit.runners.model.Statement aStatement,
org.junit.runner.Description description) |
protected RandomBug.RepeatRule |
onTest() |
public static final String MODE_PROPERTY
public final RandomBug.Mode DEFAULT
MODE_PROPERTY
is not set.public RandomBug()
protected RandomBug.RepeatRule onTest()
protected RandomBug.RepeatRule onMethod()
protected RandomBug.Mode fetchMode()
protected RandomBug.RepeatStatement onRepeat(RandomBug.Repeat someParams, org.junit.runner.notification.RunNotifier aNotifier, org.junit.runners.model.Statement aStatement, org.junit.runner.Description description)
Copyright © 2016 Nuxeo SA. All rights reserved.