Search in sources :

Example 1 with JUnitSystem

use of org.junit.internal.JUnitSystem in project h2o-3 by h2oai.

the class H2OTestRunner method run.

public Result run(String[] args) throws Exception {
    // List all classes - adapted from JUnitCore code
    List<Class<?>> classes = new ArrayList<Class<?>>();
    List<Failure> missingClasses = new ArrayList<Failure>();
    for (String arg : args) {
        try {
            classes.add(Class.forName(arg));
        } catch (ClassNotFoundException e) {
            Description description = Description.createSuiteDescription(arg);
            Failure failure = new Failure(description, e);
            missingClasses.add(failure);
        }
    }
    // Create standard JUnitCore
    JUnitCore jcore = new JUnitCore();
    // Create default "system"
    JUnitSystem jsystem = new RealSystem();
    // Setup default listener
    jcore.addListener(new TextListener(jsystem));
    // Add XML generator listener
    jcore.addListener(new XMLTestReporter());
    Result result = jcore.run(classes.toArray(new Class[0]));
    for (Failure each : missingClasses) {
        System.err.println("FAIL Missing class in H2OTestRunner: " + each);
        result.getFailures().add(each);
    }
    return result;
}
Also used : Description(org.junit.runner.Description) JUnitCore(org.junit.runner.JUnitCore) ArrayList(java.util.ArrayList) JUnitSystem(org.junit.internal.JUnitSystem) TextListener(org.junit.internal.TextListener) Result(org.junit.runner.Result) RealSystem(org.junit.internal.RealSystem) Failure(org.junit.runner.notification.Failure)

Example 2 with JUnitSystem

use of org.junit.internal.JUnitSystem in project ACS by ACS-Community.

the class TATJUnitRunner method runMain.

/**
	 * Modified version of {@link JUnitCore#runMain(JUnitSystem, String...)}.
	 * We restrict ourselves to running only one test class (or suite) at a time.
	 * This method is not thread-safe!
	 * @param testClass
	 * @return the result
	 * @throws IOException 
	 */
public Result runMain(Class<?> testClass) throws IOException {
    Result result = null;
    try {
        keepTestOutput = testClass.isAnnotationPresent(KeepTestOutput.class);
        createStreams(testClass);
        redirectSysStreams();
        JUnitSystem system = new JUnitSystem() {

            public void exit(int code) {
                System.exit(code);
            }

            public PrintStream out() {
                return resultOut;
            }
        };
        system.out().println("JUnit version " + Version.id());
        RunListener listener = new TextListener(system);
        // or should we listen directly?
        delegate.addListener(listener);
        result = delegate.run(testClass);
    } finally {
        restoreSysStreams();
        closeStreams();
    }
    // in either case print a summary which automated tools can analyze (SPR ALMASW2005121)
    int total = result.getRunCount();
    int success = total - result.getFailureCount();
    String runnerReport = "TEST_RUNNER_REPORT success/total: " + success + "/" + total;
    System.out.println(runnerReport);
    if (result.wasSuccessful()) {
        System.out.println("JUnit test run succeeded");
        if (!keepTestOutput) {
            sysOutFile.delete();
            sysErrFile.delete();
            resultFile.delete();
        }
    } else {
        System.err.println("JUnitRunner: Errors and/or failures during test execution!\n");
        // Dump the JUnit test runner output, the captured stdout, and the captured stderr of the text execution to System.err. 
        dumpAndDeleteCapturedFile(resultFile, "Test execution trace:");
        dumpAndDeleteCapturedFile(sysOutFile, "System.out during test execution:");
        dumpAndDeleteCapturedFile(sysErrFile, "System.err during test execution:");
    }
    return result;
}
Also used : JUnitSystem(org.junit.internal.JUnitSystem) TextListener(org.junit.internal.TextListener) Result(org.junit.runner.Result) RunListener(org.junit.runner.notification.RunListener)

Aggregations

JUnitSystem (org.junit.internal.JUnitSystem)2 TextListener (org.junit.internal.TextListener)2 Result (org.junit.runner.Result)2 ArrayList (java.util.ArrayList)1 RealSystem (org.junit.internal.RealSystem)1 Description (org.junit.runner.Description)1 JUnitCore (org.junit.runner.JUnitCore)1 Failure (org.junit.runner.notification.Failure)1 RunListener (org.junit.runner.notification.RunListener)1