Example usage for junit.framework Test run

List of usage examples for junit.framework Test run

Introduction

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

Prototype

public abstract void run(TestResult result);

Source Link

Document

Runs a test and collects its result in a TestResult instance.

Usage

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();// w w w . j  a  v  a  2  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.fhcrc.cpl.toolbox.filehandler.TabLoader.java

public static void main(String[] args) throws Exception {
    try {/*from w  w  w.j av  a  2  s .  c  o m*/
        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);
    }
}