FileDocCategorySizeDatePackage
CoreTestResult.javaAPI DocAndroid 1.5 API5462Wed May 06 22:41:04 BST 2009com.google.coretests

CoreTestResult

public 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
fFlags
The flags the user specified for this test run.
protected int
fTimeout
The timeout the user specified for this test run.
protected int
fTotalTestCount
The total number of tests in the original suite.
protected int
fAndroidOnlyCount
The number of Android-only tests in the original suite.
protected int
fBrokenTestCount
The number of broken tests in the original suite.
protected int
fKnownFailureCount
The number of known failures in the original suite.
protected int
fSideEffectCount
The number of side-effective tests in the original suite.
protected int
fNormalTestCount
The number of normal (non-annotated) tests in the original suite.
protected int
fIgnoredCount
The 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
booleanhasAnnotation(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 voidrunProtected(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();
                }
            }        
        }
    
voidupdateStats(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;