Search in sources :

Example 11 with TestListener

use of junit.framework.TestListener in project android_frameworks_base by crdroidandroid.

the class UiAutomatorTestRunner method start.

/**
     * Called after all test classes are in place, ready to test
     */
protected void start() {
    TestCaseCollector collector = getTestCaseCollector(this.getClass().getClassLoader());
    try {
        collector.addTestClasses(mTestClasses);
    } catch (ClassNotFoundException e) {
        // will be caught by uncaught handler
        throw new RuntimeException(e.getMessage(), e);
    }
    if (mDebug) {
        Debug.waitForDebugger();
    }
    mHandlerThread = new HandlerThread(HANDLER_THREAD_NAME);
    mHandlerThread.setDaemon(true);
    mHandlerThread.start();
    UiAutomationShellWrapper automationWrapper = new UiAutomationShellWrapper();
    automationWrapper.connect();
    long startTime = SystemClock.uptimeMillis();
    TestResult testRunResult = new TestResult();
    ResultReporter resultPrinter;
    String outputFormat = mParams.getString("outputFormat");
    List<TestCase> testCases = collector.getTestCases();
    Bundle testRunOutput = new Bundle();
    if ("simple".equals(outputFormat)) {
        resultPrinter = new SimpleResultPrinter(System.out, true);
    } else {
        resultPrinter = new WatcherResultPrinter(testCases.size());
    }
    try {
        automationWrapper.setRunAsMonkey(mMonkey);
        mUiDevice = UiDevice.getInstance();
        mUiDevice.initialize(new ShellUiAutomatorBridge(automationWrapper.getUiAutomation()));
        String traceType = mParams.getString("traceOutputMode");
        if (traceType != null) {
            Tracer.Mode mode = Tracer.Mode.valueOf(Tracer.Mode.class, traceType);
            if (mode == Tracer.Mode.FILE || mode == Tracer.Mode.ALL) {
                String filename = mParams.getString("traceLogFilename");
                if (filename == null) {
                    throw new RuntimeException("Name of log file not specified. " + "Please specify it using traceLogFilename parameter");
                }
                Tracer.getInstance().setOutputFilename(filename);
            }
            Tracer.getInstance().setOutputMode(mode);
        }
        // add test listeners
        testRunResult.addListener(resultPrinter);
        // add all custom listeners
        for (TestListener listener : mTestListeners) {
            testRunResult.addListener(listener);
        }
        // run tests for realz!
        for (TestCase testCase : testCases) {
            prepareTestCase(testCase);
            testCase.run(testRunResult);
        }
    } catch (Throwable t) {
        // catch all exceptions so a more verbose error message can be outputted
        resultPrinter.printUnexpectedError(t);
        testRunOutput.putString("shortMsg", t.getMessage());
    } finally {
        long runTime = SystemClock.uptimeMillis() - startTime;
        resultPrinter.print(testRunResult, runTime, testRunOutput);
        automationWrapper.disconnect();
        automationWrapper.setRunAsMonkey(false);
        mHandlerThread.quit();
    }
}
Also used : Bundle(android.os.Bundle) Tracer(com.android.uiautomator.core.Tracer) TestResult(junit.framework.TestResult) UiAutomationShellWrapper(com.android.uiautomator.core.UiAutomationShellWrapper) HandlerThread(android.os.HandlerThread) TestCase(junit.framework.TestCase) ShellUiAutomatorBridge(com.android.uiautomator.core.ShellUiAutomatorBridge) TestListener(junit.framework.TestListener)

Example 12 with TestListener

use of junit.framework.TestListener in project double-espresso by JakeWharton.

the class GoogleInstrumentationTestRunner method start.

@Override
public void start() {
    List<TestCase> testCases = bridgeTestRunner.getAndroidTestRunner().getTestCases();
    // Register a listener to update the current test description.
    bridgeTestRunner.getAndroidTestRunner().addTestListener(new TestListener() {

        @Override
        public void startTest(Test test) {
            runOnMainSync(new ActivityFinisher());
        }

        @Override
        public void endTest(Test test) {
        }

        @Override
        public void addFailure(Test test, AssertionFailedError ae) {
        }

        @Override
        public void addError(Test test, Throwable t) {
        }
    });
    super.start();
}
Also used : TestCase(junit.framework.TestCase) Test(junit.framework.Test) TestListener(junit.framework.TestListener) AssertionFailedError(junit.framework.AssertionFailedError)

Example 13 with TestListener

use of junit.framework.TestListener in project android_frameworks_base by crdroidandroid.

the class AndroidTestRunner method runTest.

public void runTest(TestResult testResult) {
    mTestResult = testResult;
    for (TestListener testListener : mTestListeners) {
        mTestResult.addListener(testListener);
    }
    Context testContext = mInstrumentation == null ? mContext : mInstrumentation.getContext();
    for (TestCase testCase : mTestCases) {
        setContextIfAndroidTestCase(testCase, mContext, testContext);
        setInstrumentationIfInstrumentationTestCase(testCase, mInstrumentation);
        setPerformanceWriterIfPerformanceCollectorTestCase(testCase, mPerfWriter);
        testCase.run(mTestResult);
    }
}
Also used : Context(android.content.Context) TestCase(junit.framework.TestCase) TestListener(junit.framework.TestListener)

Example 14 with TestListener

use of junit.framework.TestListener in project platform_frameworks_base by android.

the class AndroidTestRunner method runTest.

public void runTest(TestResult testResult) {
    mTestResult = testResult;
    for (TestListener testListener : mTestListeners) {
        mTestResult.addListener(testListener);
    }
    Context testContext = mInstrumentation == null ? mContext : mInstrumentation.getContext();
    for (TestCase testCase : mTestCases) {
        setContextIfAndroidTestCase(testCase, mContext, testContext);
        setInstrumentationIfInstrumentationTestCase(testCase, mInstrumentation);
        setPerformanceWriterIfPerformanceCollectorTestCase(testCase, mPerfWriter);
        testCase.run(mTestResult);
    }
}
Also used : Context(android.content.Context) TestCase(junit.framework.TestCase) TestListener(junit.framework.TestListener)

Example 15 with TestListener

use of junit.framework.TestListener in project junit4 by junit-team.

the class ForwardCompatibilityTest method testNotifyResult.

public void testNotifyResult() {
    JUnit4TestAdapter adapter = new JUnit4TestAdapter(ErrorTest.class);
    TestResult result = new TestResult();
    final StringBuffer log = new StringBuffer();
    result.addListener(new TestListener() {

        public void startTest(junit.framework.Test test) {
            log.append(" start ").append(test);
        }

        public void endTest(junit.framework.Test test) {
            log.append(" end ").append(test);
        }

        public void addFailure(junit.framework.Test test, AssertionFailedError t) {
            log.append(" failure ").append(test);
        }

        public void addError(junit.framework.Test test, Throwable e) {
            log.append(" error " + test);
        }
    });
    adapter.run(result);
    String testName = String.format("error(%s)", ErrorTest.class.getName());
    assertEquals(String.format(" start %s error %s end %s", testName, testName, testName), log.toString());
}
Also used : TestResult(junit.framework.TestResult) TestListener(junit.framework.TestListener) JUnit4TestAdapter(junit.framework.JUnit4TestAdapter) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

TestListener (junit.framework.TestListener)23 TestCase (junit.framework.TestCase)17 AssertionFailedError (junit.framework.AssertionFailedError)13 Test (junit.framework.Test)11 TestResult (junit.framework.TestResult)6 Context (android.content.Context)5 Bundle (android.os.Bundle)5 HandlerThread (android.os.HandlerThread)5 AndroidTestRunner (android.test.AndroidTestRunner)5 ShellUiAutomatorBridge (com.android.uiautomator.core.ShellUiAutomatorBridge)5 Tracer (com.android.uiautomator.core.Tracer)5 UiAutomationShellWrapper (com.android.uiautomator.core.UiAutomationShellWrapper)5 Field (java.lang.reflect.Field)5 BrokenTest (dalvik.annotation.BrokenTest)1 JUnit4TestAdapter (junit.framework.JUnit4TestAdapter)1 Test (org.junit.Test)1 JUnit38ClassRunner (org.junit.internal.runners.JUnit38ClassRunner)1 Result (org.junit.runner.Result)1 RunListener (org.junit.runner.notification.RunListener)1 RunNotifier (org.junit.runner.notification.RunNotifier)1