public class RandomBug extends Object implements org.junit.rules.MethodRule
Principle is to increase consistency on tests which have a random behavior. Such test is a headache because:
Ignore
JUnit annotation, the advantage is to provide
different behaviors for different use cases. The wanted behavior depending on
whereas:
For instance:
In the above example, the test fails sometimes.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 @RandomBugRule.Repeat(issue = NXP99999, onFailure=5, onSuccess=50) public void testWhichFailsSometimes() throws Exception { assertTrue(java.lang.Math.random() > 0.2); } }
@RandomBugRule.Repeat
annotation, it will be repeated in
case of failure up to 5 times until success. This is the default
RandomBug.MODE.RELAX
mode.RandomBug.MODE.STRICT
mode. It will be
repeated in case of success up to 50 times until failure.RandomBug.MODE.BYPASS
mode, the test is ignored.
RandomBug.MODE
,
MODE_PROPERTY
Modifier and Type | Class and Description |
---|---|
static class |
RandomBug.MODE
BYPASS: the test is ignored.
|
static interface |
RandomBug.Repeat
Repeat condition based on
|
Modifier and Type | Field and Description |
---|---|
static RandomBug.MODE |
DEFAULT
The default mode if
MODE_PROPERTY is not set. |
static String |
MODE_PROPERTY |
Constructor and Description |
---|
RandomBug() |
Modifier and Type | Method and Description |
---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement statement,
org.junit.runners.model.FrameworkMethod method,
Object target) |
static RandomBug.MODE |
getMode() |
public static final String MODE_PROPERTY
public static final RandomBug.MODE DEFAULT
MODE_PROPERTY
is not set.public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement statement, org.junit.runners.model.FrameworkMethod method, Object target)
apply
in interface org.junit.rules.MethodRule
public static RandomBug.MODE getMode()
Copyright © 2014 Nuxeo SA. All rights reserved.