LUCENE-4160: making tests more robust by restoring before-the-test number of failures.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1355263 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dawid Weiss 2012-06-29 08:25:07 +00:00
parent 63eefa822f
commit b599cdf80f
2 changed files with 13 additions and 19 deletions

View File

@ -45,9 +45,11 @@ public class TestMaxFailuresRule extends WithNestedTests {
@Test
public void testMaxFailures() {
int maxFailures = LuceneTestCase.ignoreAfterMaxFailures.getMaxFailures();
int maxFailures = LuceneTestCase.ignoreAfterMaxFailures.maxFailures;
int failuresSoFar = LuceneTestCase.ignoreAfterMaxFailures.failuresSoFar;
try {
LuceneTestCase.ignoreAfterMaxFailures.setMaxFailures(2);
LuceneTestCase.ignoreAfterMaxFailures.maxFailures = 2;
LuceneTestCase.ignoreAfterMaxFailures.failuresSoFar = 0;
JUnitCore core = new JUnitCore();
final int [] assumptions = new int [1];
@ -59,14 +61,16 @@ public class TestMaxFailuresRule extends WithNestedTests {
});
Result result = core.run(Nested.class);
Assert.assertEquals(2, result.getFailureCount());
Assert.assertEquals(0, result.getIgnoreCount());
Assert.assertEquals(100, result.getRunCount());
Assert.assertEquals(0, result.getIgnoreCount());
Assert.assertEquals(2, result.getFailureCount());
// JUnit doesn't pass back the number of successful tests, just make sure
// we did have enough assumption-failures.
Assert.assertTrue(assumptions[0] > 50);
} finally {
LuceneTestCase.ignoreAfterMaxFailures.setMaxFailures(maxFailures);
LuceneTestCase.ignoreAfterMaxFailures.maxFailures = maxFailures;
LuceneTestCase.ignoreAfterMaxFailures.failuresSoFar = failuresSoFar;
}
}
}

View File

@ -37,14 +37,14 @@ import com.carrotsearch.randomizedtesting.annotations.Repeat;
*/
public final class TestRuleIgnoreAfterMaxFailures implements TestRule {
/**
* Maximum failures.
* Maximum failures. Package scope for tests.
*/
private int maxFailures;
int maxFailures;
/**
* Current count of failures.
* Current count of failures. Package scope for tests.
*/
private int failuresSoFar;
int failuresSoFar;
/**
* @param maxFailures
@ -70,7 +70,6 @@ public final class TestRuleIgnoreAfterMaxFailures implements TestRule {
s.evaluate();
} catch (Throwable t) {
if (!TestRuleMarkFailure.isAssumption(t)) {
System.out.println("#" + d);
failuresSoFar++;
}
throw t;
@ -78,13 +77,4 @@ public final class TestRuleIgnoreAfterMaxFailures implements TestRule {
}
};
}
/** For tests only. */
void setMaxFailures(int maxFailures) {
this.maxFailures = maxFailures;
}
int getMaxFailures() {
return maxFailures;
}
}