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

StatTestRunner

public class StatTestRunner extends BaseTestRunner
A command line based tool to run tests.
java junit.textui.TestRunner [-wait] TestCaseClass
TestRunner expects the name of a TestCase class as argument. If this class defines a static suite method it will be invoked and the returned test is run. Otherwise all the methods starting with "test" having no arguments are run.

When the wait command line argument is given TestRunner waits until the users types RETURN.

TestRunner prints a trace as the tests are executed followed by a summary at the end.

Fields Summary
private ResultPrinter
fPrinter
private PerfStatCollector
fPerfStatCollector
public static final int
SUCCESS_EXIT
public static final int
FAILURE_EXIT
public static final int
EXCEPTION_EXIT
public static final String
DEFAULT_DATABASE
public static final String
DEFAULT_DRIVER
public static String
connectionURL
public static String
jdbcDriver
Constructors Summary
public StatTestRunner()
Constructs a TestRunner.


            
      
        this(System.out);
    
public StatTestRunner(PrintStream writer)
Constructs a TestRunner using the given stream for all the output

        this(new ResultPrinter(writer));
    
public StatTestRunner(ResultPrinter printer)
Constructs a TestRunner using the given ResultPrinter all the output

        fPrinter= printer;
        fPerfStatCollector = new PerfStatCollector(printer.getWriter());
    
Methods Summary
public junit.framework.TestResultdoRun(junit.framework.Test suite, boolean wait)

        StatsStore.open(jdbcDriver, connectionURL);
        TestResult result = new TestResult();
        result.addListener(fPrinter);
        result.addListener(fPerfStatCollector);
        long startTime= System.currentTimeMillis();
        StatsStore.now = startTime;
        suite.run(result);
        long endTime= System.currentTimeMillis();
        long runTime= endTime-startTime;
        fPrinter.print(result, runTime);
        fPerfStatCollector.digest();
        StatsStore.close();

        pause(wait);
        return result;
    
public junit.runner.TestSuiteLoadergetLoader()
Always use the StandardTestSuiteLoader. Overridden from BaseTestRunner.

        return new StandardTestSuiteLoader();
    
public static voidmain(java.lang.String[] args)

        StatTestRunner aTestRunner= new StatTestRunner();
        try {
            TestResult r= aTestRunner.start(args);
            if (!r.wasSuccessful())
                System.exit(FAILURE_EXIT);
            System.exit(SUCCESS_EXIT);
        } catch(Exception e) {
            System.err.println(e.getMessage());
            System.exit(EXCEPTION_EXIT);
        }
    
protected voidpause(boolean wait)

        if (!wait) return;
        fPrinter.printWaitPrompt();
        try {
            System.in.read();
        }
        catch(Exception e) {
        }
    
public static voidrun(java.lang.Class testClass)
Runs a suite extracted from a TestCase subclass.

        run(new TestSuite(testClass));
    
public static junit.framework.TestResultrun(junit.framework.Test test)
Runs a single test and collects its results. This method can be used to start a test run from your program.
public static void main (String[] args) {
test.textui.TestRunner.run(suite());
}

        StatTestRunner runner= new StatTestRunner();
        try {
            return runner.doRun(test, false);
        }
        catch (Exception e) {
            return null;
        }
    
public static voidrunAndWait(junit.framework.Test suite)
Runs a single test and waits until the user types RETURN.

        StatTestRunner aTestRunner= new StatTestRunner();
        try {
            aTestRunner.doRun(suite, true);
        }
        catch (Exception e) {}
    
protected voidrunFailed(java.lang.String message)

        System.err.println(message);
        System.exit(FAILURE_EXIT);
    
public voidsetPrinter(ResultPrinter printer)

        fPrinter= printer;
    
protected junit.framework.TestResultstart(java.lang.String[] args)
Starts a test run. Analyzes the command line arguments and runs the given test suite.

        String testCase= "";
        boolean wait= false;

        jdbcDriver = System.getProperty("android.coretests.driver", DEFAULT_DRIVER); 
        connectionURL = System.getProperty("android.coretests.database", "jdbc:" + DEFAULT_DATABASE); 
            
        for (int i= 0; i < args.length; i++) {
            if (args[i].equals("--all"))
                fPerfStatCollector.listAll = true;
            else if (args[i].equals("--bad"))
                fPerfStatCollector.listBad = true;
            else if (args[i].equals("--nobig"))
                fPerfStatCollector.bigMarking = false;
            else if (args[i].equals("--s")) {
                fPerfStatCollector.thresholdDuration =
                    Integer.valueOf(args[++i]);
            } else if (args[i].equals("-wait"))
                wait= true;
            else if (args[i].equals("-c")) 
                testCase= extractClassName(args[++i]);
            else if (args[i].equals("-v"))
                System.err.println("JUnit "+Version.id()+" (plus Android performance stats)");
            else
                testCase= args[i];
        }
        
        if (testCase.equals("")) 
            throw new Exception("Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class");

        try {
            Test suite= getTest(testCase);
            return doRun(suite, wait);
        }
        catch (Exception e) {
            throw new Exception("Exception: " + e);
        }
    
public voidtestEnded(java.lang.String testName)

    
public voidtestFailed(int status, junit.framework.Test test, java.lang.Throwable t)

    
public voidtestStarted(java.lang.String testName)