CoreTestResultpublic class CoreTestResult extends TestResult A special TestResult implementation that is able to filter out annotated
tests and handles our known failures properly (expects them to fail).
Handy when running the Core Libraries tests on Android, the bare-metal
Dalvik VM, or the RI. |
Fields Summary |
---|
protected int | fFlagsThe flags the user specified for this test run. | protected int | fTimeoutThe timeout the user specified for this test run. | protected int | fTotalTestCountThe total number of tests in the original suite. | protected int | fAndroidOnlyCountThe number of Android-only tests in the original suite. | protected int | fBrokenTestCountThe number of broken tests in the original suite. | protected int | fKnownFailureCountThe number of known failures in the original suite. | protected int | fSideEffectCountThe number of side-effective tests in the original suite. | protected int | fNormalTestCountThe number of normal (non-annotated) tests in the original suite. | protected int | fIgnoredCountThe number of ignored tests, that is, the number of tests that were
excluded from this suite due to their annotations. |
Constructors Summary |
---|
public CoreTestResult(int flags, int timeout)Creates a new CoreTestResult with the given flags and timeout.
super();
fFlags = flags;
fTimeout = timeout;
|
Methods Summary |
---|
boolean | hasAnnotation(junit.framework.TestCase test, java.lang.Class clazz)Checks whether the given TestCase method has the given annotation.
try {
Method method = test.getClass().getMethod(test.getName());
return method.getAnnotation(clazz) != null;
} catch (Exception e) {
// Ignore
}
return false;
| public void | runProtected(junit.framework.Test test, junit.framework.Protectable p)
if ((fFlags & CoreTestSuite.DRY_RUN) == 0) {
if (test instanceof TestCase) {
TestCase testCase = (TestCase)test;
// Check whether we need to invert the test result (known failures)
boolean invert = hasAnnotation(testCase, KnownFailure.class) &&
(fFlags & CoreTestSuite.INVERT_KNOWN_FAILURES) != 0;
// Check whether we need to isolate the test (side effects)
boolean isolate = hasAnnotation(testCase, SideEffect.class) &&
(fFlags & CoreTestSuite.ISOLATE_NONE) == 0 ||
(fFlags & CoreTestSuite.ISOLATE_ALL) != 0;
CoreTestRunnable runnable = new CoreTestRunnable(
testCase, this, p, invert, isolate);
if (fTimeout > 0) {
Thread thread = new Thread(runnable);
thread.start();
try {
thread.join(fTimeout * 1000);
} catch (InterruptedException ex) {
// Ignored
}
if (thread.isAlive()) {
runnable.stop();
thread.stop();
try {
thread.join(fTimeout * 1000);
} catch (InterruptedException ex) {
// Ignored
}
addError(test, new CoreTestTimeout("Test timed out"));
}
} else {
runnable.run();
}
}
}
| void | updateStats(int total, int androidOnly, int broken, int knownFailure, int normal, int ignored, int sideEffect)Updates the statistics in this TestResult. Called from the TestSuite,
since, once the original suite has been filtered, we don't actually see
these tests here anymore.
this.fTotalTestCount += total;
this.fAndroidOnlyCount += androidOnly;
this.fBrokenTestCount += broken;
this.fKnownFailureCount += knownFailure;
this.fNormalTestCount += normal;
this.fIgnoredCount += ignored;
this.fSideEffectCount += sideEffect;
|
|