Example usage for junit.framework TestResult TestResult

List of usage examples for junit.framework TestResult TestResult

Introduction

In this page you can find the example usage for junit.framework TestResult TestResult.

Prototype

public TestResult() 

Source Link

Usage

From source file:Main.java

public static void main(String[] a) {
    // add the test's in the suite
    TestSuite suite = new TestSuite(TestJunit1.class, TestJunit2.class, TestJunit3.class);
    TestResult result = new TestResult();
    suite.run(result);/*  ww  w .j  a va  2  s  .c  om*/
    System.out.println("Number of test cases = " + result.runCount());
}

From source file:de.unisb.cs.st.javalanche.mutation.runtime.testDriver.junit.Junit3MutationTestDriver.java

@Override
protected MutationTestRunnable getTestRunnable(final String testName) {
    MutationTestRunnable r = new MutationTestRunnable() {

        boolean finished = false;

        final TestResult result = new TestResult();

        private SingleTestListener listener = new SingleTestListener();

        private boolean failed = false;

        private StopWatch stopWatch = new StopWatch();

        public void run() {
            try {
                stopWatch.start();/*from  www .jav  a2  s  . c o m*/
                Test actualtest = allTests.get(testName);
                if (actualtest == null) {
                    String message = "Test not found in: " + testName + "\n All Tests:" + allTests;
                    System.out.println(message);
                    logger.warn(message);
                    System.exit(0);
                }
                result.addListener(listener);
                actualtest.run(result);
            } catch (Exception e) {
                logger.debug("Cought exception from test " + e + " Message " + e.getMessage());
            } finally {
                stopWatch.stop();
                finished = true;
            }
        }

        public synchronized boolean hasFinished() {
            return finished;
        }

        public SingleTestResult getResult() {

            String message = listener.getMessage();
            if (message == null) {
                message = "";
            }

            TestOutcome outcome = TestOutcome.PASS;
            if (result.failureCount() > 0) {
                outcome = TestOutcome.FAIL;
            } else if (result.errorCount() > 0) {
                outcome = TestOutcome.ERROR;
            }
            SingleTestResult res = new SingleTestResult(testName, message, outcome, stopWatch.getTime());
            return res;
        }

        @Override
        public void setFailed(String message, Throwable e) {
            result.addError(allTests.get(testName), e);
        }

    };
    return r;
}

From source file:org.eclipse.gemini.blueprint.test.internal.support.OsgiJUnitService.java

/**
 * Run fixture setup, test from the given test case and fixture teardown.
 * /*from w  w w  .  ja  v a 2  s . c  o  m*/
 * @param osgiTestExtensions
 * @param testName
 */
protected TestResult runTest(final OsgiJUnitTest osgiTestExtensions, String testName) {
    if (log.isDebugEnabled())
        log.debug("Running test [" + testName + "] on testCase " + osgiTestExtensions);
    final TestResult result = new TestResult();
    TestCase rawTest = osgiTestExtensions.getTestCase();

    rawTest.setName(testName);

    try {
        osgiTestExtensions.osgiSetUp();

        try {
            // use TestResult method to bypass the setUp/tearDown methods
            result.runProtected(rawTest, new Protectable() {

                public void protect() throws Throwable {
                    osgiTestExtensions.osgiRunTest();
                }

            });
        } finally {
            osgiTestExtensions.osgiTearDown();
        }

    }
    // exceptions thrown by osgiSetUp/osgiTearDown
    catch (Exception ex) {
        log.error("test exception threw exception ", ex);
        result.addError((Test) rawTest, ex);
    }
    return result;
}

From source file:org.fhcrc.cpl.toolbox.filehandler.TabLoader.java

public static void main(String[] args) throws Exception {
    try {//from   w  w w.ja  va 2  s.  c om
        Class c = Class.forName("org.fhcrc.cpas.data.ConvertHelper");
        c.getMethod("registerHelpers").invoke(null);

        Test test = TabLoaderTestCase.suite();
        TestResult result = new TestResult();
        test.run(result);
        System.out.println(result.wasSuccessful() ? "success" : "fail");

        Enumeration failures = result.failures();
        Throwable first = null;
        while (failures.hasMoreElements()) {
            TestFailure failure = (TestFailure) failures.nextElement();
            System.err.println(failure.toString());
            if (first == null)
                first = failure.thrownException();
        }
        Enumeration errors = result.errors();
        while (errors.hasMoreElements()) {
            TestFailure error = (TestFailure) errors.nextElement();
            System.err.println(error.toString());
            if (first == null)
                first = error.thrownException();
        }
        if (first != null) {
            System.err.println("first exception");
            first.printStackTrace(System.err);
        }
    } catch (Throwable t) {
        t.printStackTrace(System.err);
    }
}