public GcjTestRunner(List<Class<?>> classes) { this.unit = new JUnitCore(); this.resultBytes = new ByteArrayOutputStream(); this.resultStream = new PrintStream(this.resultBytes); this.unit.addListener(new TextListener(this.resultStream)); this.classes = new ArrayList<>(classes); }
String runTests() { PrintStream sysOut = System.out; PrintStream sysErr = System.err; ByteArrayOutputStream stream = new ByteArrayOutputStream(); PrintStream out = new PrintStream(stream); try { System.setOut(out); System.setErr(out); TextListener listener = new TextListener(out); JUnitCore junit = new JUnitCore(); junit.addListener(listener); junit.run(MyClassIT.class, AnotherClassIT.class, ...etc...); } finally { System.setOut(sysOut); System.setErr(sysErr); out.close(); } return stream.toString(); }
/** * @param system * @args args from main() */ private Result runMain(JUnitSystem system, String... args) { system.out().println("JUnit version " + Version.id()); List<Class<?>> classes = new ArrayList<Class<?>>(); List<Failure> missingClasses = new ArrayList<Failure>(); for (String each : args) { try { classes.add(Class.forName(each)); } catch (ClassNotFoundException e) { system.out().println("Could not find class: " + each); Description description = Description.createSuiteDescription(each); Failure failure = new Failure(description, e); missingClasses.add(failure); } } RunListener listener = new TextListener(system); addListener(listener); Result result = run(classes.toArray(new Class[0])); for (Failure each : missingClasses) { result.getFailures().add(each); } return result; }
/** * Run all the tests contained in <code>request</code>. * * This variant should be used if {@code core} has attached listeners that this * run should notify. * * @param request the request describing tests * @param core a JUnitCore to delegate to. * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Request request, JUnitCore core) { core.addListener(history.listener()); return core.run(sortRequest(request).getRunner()); }
/** * Run all the tests contained in <code>request</code>. * * This variant should be used if {@code core} has attached listeners that this * run should notify. * * @param request the request describing tests * @param core a JUnitCore to delegate to. * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Request request, JUnitCore core) { core.addListener(fHistory.listener()); return core.run(sortRequest(request).getRunner()); }
/** * @param system * @param args from main() */ Result runMain(JUnitSystem system, String... args) { system.out().println("JUnit version " + Version.id()); JUnitCommandLineParseResult jUnitCommandLineParseResult = JUnitCommandLineParseResult.parse(args); RunListener listener = new TextListener(system); addListener(listener); return run(jUnitCommandLineParseResult.createRequest(defaultComputer())); }
EventDispatcher ed = new EventDispatcher(logger, eventHandler, settings, fingerprint); JUnitCore ju = new JUnitCore(); ju.addListener(ed); if (runListener != null) { ju.addListener(createRunListener(runListener));
try { JUnitCore core = new JUnitCore(); core.addListener(new RL()); Request r = Request.aClass(testCase); return core.run(r.filterWith(new Filter() {
try { JUnitCore core = new JUnitCore(); core.addListener(new RL()); Request r = Request.aClass(testCase); return core.run(
@Override protected int doWork() throws Exception { //this is called from the command line, so we should set to use the distributed cluster IntegrationTestingUtility.setUseDistributedCluster(conf); Class<?>[] classes = findIntegrationTestClasses(); LOG.info("Found " + classes.length + " integration tests to run:"); for (Class<?> aClass : classes) { LOG.info(" " + aClass); } JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); Result result = junit.run(classes); return result.wasSuccessful() ? 0 : 1; } }
public void execute(RunnerTestDescriptor runnerTestDescriptor) { TestRun testRun = new TestRun(runnerTestDescriptor); JUnitCore core = new JUnitCore(); core.addListener(new RunListenerAdapter(testRun, engineExecutionListener)); try { core.run(runnerTestDescriptor.toRequest()); } catch (Throwable t) { BlacklistedExceptions.rethrowIfBlacklisted(t); reportUnexpectedFailure(testRun, runnerTestDescriptor, failed(t)); } }
protected Result run(TestRunnerAdaptor adaptor, RunListener listener, Class<?>... classes) throws Exception { try { setAdaptor(adaptor); JUnitCore core = new JUnitCore(); if (listener != null) { core.addListener(listener); } return core.run(classes); } finally { setAdaptor(null); } }
junit.addListener(new LogListener()); Result result = junit.run(tests.toArray(new Class[0])); if( result.getFailures().size() == 0 ) {
junit.addListener(listener); junit.run(testClass);
junit.addListener(listener); junit.run(computer, testClasses);
JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); junit.run(TestReader.class);
/** * @param system * @args args from main() */ private Result runMain(JUnitSystem system, String... args) { system.out().println("JUnit version " + Version.id()); List<Class<?>> classes = new ArrayList<Class<?>>(); List<Failure> missingClasses = new ArrayList<Failure>(); for (String each : args) { try { classes.add(Class.forName(each)); } catch (ClassNotFoundException e) { system.out().println("Could not find class: " + each); Description description = Description.createSuiteDescription(each); Failure failure = new Failure(description, e); missingClasses.add(failure); } } RunListener listener = new TextListener(system); addListener(listener); Result result = run(classes.toArray(new Class[0])); for (Failure each : missingClasses) { result.getFailures().add(each); } return result; }
import org.junit.extensions.cpsuite.ClasspathSuite; import org.junit.extensions.cpsuite.ClasspathSuite.*; import org.junit.runner.RunWith; import org.junit.runner.JUnitCore; import org.junit.internal.TextListener; import static org.junit.extensions.cpsuite.SuiteType.*; @RunWith(ClasspathSuite.class) @SuiteTypes({ JUNIT38_TEST_CLASSES, TEST_CLASSES }) public class RunAllSuite { public static void main(String args[]) { JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); junit.run(RunAllSuite.class); } }
/** * Run all the tests contained in <code>request</code>. * * This variant should be used if {@code core} has attached listeners that this * run should notify. * * @param request the request describing tests * @param core a JUnitCore to delegate to. * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Request request, JUnitCore core) { core.addListener(fHistory.listener()); return core.run(sortRequest(request).getRunner()); }
@Override protected int doWork() throws Exception { //this is called from the command line, so we should set to use the distributed cluster IntegrationTestingUtility.setUseDistributedCluster(conf); Class<?>[] classes = findEnd2EndTestClasses(); System.out.println("Found " + classes.length + " end2end tests to run:"); for (Class<?> aClass : classes) { System.out.println(" " + aClass); } if(skipTests) return 0; JUnitCore junit = new JUnitCore(); junit.addListener(new End2EndTestListenter(System.out)); Result result = junit.run(classes); return result.wasSuccessful() ? 0 : 1; } }