Search in sources :

Example 26 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)

Example 27 with TestListener

use of junit.framework.TestListener in project openj9 by eclipse.

the class TestDefenderSupersends method main.

/**
 * @param args
 */
public static void main(String[] args) {
    Class<?> testClass = AsmUtils.getDefenderSupersendTestcase();
    Test suite = new TestSuite(testClass);
    TestResult result = new TestResult();
    result.addListener(new TestListener() {

        public void addError(Test test, Throwable t) {
            t.printStackTrace(System.err);
        }

        public void addFailure(Test test, AssertionFailedError t) {
            t.printStackTrace(System.err);
        }

        public void endTest(Test test) {
            System.out.println("Finished " + test);
        }

        public void startTest(Test test) {
            System.out.println("Starting " + test);
        }
    });
    suite.run(result);
    System.out.println("================Test Result ==================");
    System.out.println("Failures:   " + result.failureCount() + " out of " + result.runCount() + " test cases.");
    System.out.println("Errors:   " + result.errorCount() + " out of " + result.runCount() + " test cases.");
// return value
}
Also used : TestSuite(junit.framework.TestSuite) Test(junit.framework.Test) TestResult(junit.framework.TestResult) TestListener(junit.framework.TestListener) AssertionFailedError(junit.framework.AssertionFailedError)

Example 28 with TestListener

use of junit.framework.TestListener in project openj9 by eclipse.

the class AutoRun method runTest.

/**
 * This method is responsible for running the test suite in Native Debugger based DDR testing
 * @param ctx - The context object
 * @param out - The PrintStream object to be used to output logs
 * @param testCaseList - Comma separated list of test suite classes to run
 */
public static void runTest(Context ctx, PrintStream out, String testCaseList) {
    // initiate DDRInteractive instance
    SetupConfig.init(ctx, out);
    log.info("Executing test cases : " + testCaseList);
    // Get the overall list of tests to ignore for native DDR tests as found in ddrext_excludes.xml
    String excludeList = getExcludesFor(Constants.TESTDOMAIN_NATIVE);
    Test suite = getTestSuite(testCaseList, excludeList);
    // Based on the excludes defined in ddrext_excludes.xml, construct the list of tests to ignore from the full list of tests in
    // the current test suite.
    getExcludesForCurrentSuites(suite, excludeList);
    int numberOfExcludesForCurrentSuite = 0;
    if (excludesForCurrentSuite != null) {
        if (excludesForCurrentSuite.contains(",") == false) {
            numberOfExcludesForCurrentSuite = 1;
        } else {
            numberOfExcludesForCurrentSuite = excludesForCurrentSuite.split(",").length;
        }
    }
    log.info("Running " + (suite.countTestCases() - numberOfExcludesForCurrentSuite) + " tests from ddrjunit plugin");
    TestResult result = new TestResult();
    result.addListener(new TestListener() {

        public void addError(Test test, Throwable t) {
            t.printStackTrace(System.err);
        }

        public void addFailure(Test test, AssertionFailedError t) {
            t.printStackTrace(System.err);
        }

        public void endTest(Test test) {
            log.info("Finished " + test + Constants.NL);
        }

        public void startTest(Test test) {
            log.info("Starting " + test);
        }
    });
    suite.run(result);
    errCount = errCount + result.errorCount();
    failCount = failCount + result.failureCount();
    log.info("================Test Result==================");
    log.info("Errors:   " + result.errorCount() + " out of " + (suite.countTestCases() - numberOfExcludesForCurrentSuite) + " test cases.");
    log.info("Failures: " + result.failureCount() + " out of " + (suite.countTestCases() - numberOfExcludesForCurrentSuite) + " test cases.");
    if (numberOfExcludesForCurrentSuite != 0) {
        log.info("Total tests excluded = " + numberOfExcludesForCurrentSuite + " [" + excludesForCurrentSuite + "]");
    }
    // After run test on the core file, reset DDRInteractive,outputString
    // and ddrResultCache to null
    SetupConfig.reset();
    DDRExtTesterBase.resetList();
    // print out success/failure info
    log.info("Total Error/Failures: " + (errCount + failCount));
    if ((errCount + failCount) > 0) {
        System.exit(-2);
    } else {
        System.exit(0);
    }
}
Also used : Test(junit.framework.Test) TestResult(junit.framework.TestResult) TestListener(junit.framework.TestListener) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

TestListener (junit.framework.TestListener)28 AssertionFailedError (junit.framework.AssertionFailedError)17 TestCase (junit.framework.TestCase)17 Test (junit.framework.Test)16 TestResult (junit.framework.TestResult)10 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 TestSuite (junit.framework.TestSuite)3 BrokenTest (dalvik.annotation.BrokenTest)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 Method (java.lang.reflect.Method)1 JUnit4TestAdapter (junit.framework.JUnit4TestAdapter)1 CommandLine (org.apache.commons.cli.CommandLine)1