public Result doRun(Test suite, boolean wait) { MarathonTestRunner runner = new MarathonTestRunner(); runReportDir = argProcessor.getReportDir(); String resultsDir = new File(runReportDir, "results").getAbsolutePath(); if (runReportDir != null) { System.setProperty(Constants.PROP_REPORT_DIR, runReportDir); System.setProperty(Constants.PROP_IMAGE_CAPTURE_DIR, runReportDir); System.setProperty("allure.results.directory", resultsDir); runner.addListener(new AllureMarathonRunListener()); } runner.addListener(new TextListener(System.out)); Result result = runSuite(suite, runner); MarathonTestCase.reset(); if (runReportDir != null && !argProcessor.isSkipreports()) { AllureUtils.launchAllure(false, resultsDir, new File(runReportDir, "reports").getAbsolutePath()); } return result; }
public void runTests(String outputDir) { JUnitCore junit = new JUnitCore(); if (outputDir == null) { junit.addListener(new TextListener(System.out)); } else { junit.addListener(new JUnitResultFormatterAsRunListener(new XMLJUnitResultFormatter()) { @Override public void testStarted(Description description) throws Exception { formatter.setOutput(new FileOutputStream( new File(outputDir, "TEST-" + description.getDisplayName() + ".xml"))); super.testStarted(description); } }); } junit.run(TestContainer.class); }
@Test public void testSystem() throws Throwable { Computer computer = new Computer(); JUnitCore jUnitCore = new JUnitCore(); ByteArrayOutputStream capture = new ByteArrayOutputStream(); final PrintStream printStream = new PrintStream(capture); TextListener listener = new TextListener(printStream); jUnitCore.addListener(listener); PrintStream systemOut = System.out; System.setOut(printStream); try { jUnitCore.run(computer, ExampleTest.class); } finally { System.setOut(systemOut); } String output = capture.toString("UTF-8"); output = normalizeOutput(output); String expectedOutput = getResource("/CompositeTest.testSystem.expected.txt"); Assert.assertEquals(expectedOutput, output); }
private void addListeners(List<RunListener> listeners, JUnitCore testRunner, PrintStream writer) { if (getBooleanArgument(ARGUMENT_SUITE_ASSIGNMENT)) { listeners.add(new SuiteAssignmentPrinter()); } else { listeners.add(new TextListener(writer)); listeners.add(new LogRunListener()); mInstrumentationResultPrinter = new InstrumentationResultPrinter(); listeners.add(mInstrumentationResultPrinter); listeners.add(new ActivityFinisherRunListener(this, new ActivityFinisher())); addDelayListener(listeners); addCoverageListener(listeners); } addListenersFromArg(listeners, writer); addListenersFromManifest(listeners, writer); for (RunListener listener : listeners) { testRunner.addListener(listener); if (listener instanceof InstrumentationRunListener) { ((InstrumentationRunListener) listener).setInstrumentation(this); } } }
/** * @param args */ public static void main(String[] args) { JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); junit.run( // LearnerTest.class, AtomTest.class, ClauseTest.class, ConfigTest.class, GAtomTest.class, GClauseTest.class, GroundingTest.class, InferenceTest.class, LiteralTest.class, ParsingLoadingTest.class, PredicateTest.class, TermTest.class, TupleTest.class, TypeTest.class ); }
private ByteArrayOutputStream getExpectedOutput(Class<?> testClass) { JUnitCore core = new JUnitCore(); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(byteStream); printStream.println("JUnit4 Test Runner"); RunListener listener = new TextListener(printStream); core.addListener(listener); Request request = Request.classWithoutSuiteMethod(testClass); core.run(request); printStream.close(); return byteStream; }
/** * A method to allow tests to be run from simple scripts without all the JUnit infrastructure * * @return The number of failed tests */ public int run() { JoranConfigurator configurator = new JoranConfigurator(); LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); try { configurator.setContext(context); context.reset(); configurator.doConfigure(classpath("/logback-morc.xml")); } catch (JoranException e) { throw new RuntimeException(e); } JUnitCore core = new JUnitCore(); core.addListener(new TextListener(System.out)); try { Result r = core.run(new MorcParameterized(this)); return r.getFailureCount(); } catch (Throwable t) { throw new RuntimeException(t); } }
@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; }
/** * Returns a new {@link RunListener} instance for the given {@param outputFormat}. */ public RunListener newRunListener(OutputFormat outputFormat) { switch (outputFormat) { case JUNIT: out.println("JUnit version " + Version.id()); return new TextListener(out); case GTM_UNIT_TESTING: return new GtmUnitTestingTextListener(); default: throw new IllegalArgumentException("outputFormat"); } }
@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"); JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); Result result = junit.run(classes); return result.wasSuccessful() ? 0 : 1; }
private static void runTest(String test) { try { String[] classAndMethod = test.split("#"); System.out.println(test); Request request = Request.method(Class.forName(classAndMethod[0]), classAndMethod[1]); JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); junit.run(request); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
@Override public void didBecomeActive(UIApplication application) { super.didBecomeActive(application); NSException.registerDefaultJavaUncaughtExceptionHandler(); Computer computer = new Computer(); JUnitCore jUnitCore = new JUnitCore(); jUnitCore.addListener(new TextListener(System.out)); jUnitCore.run(computer, getTestClasses()); }
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) { result.getFailures().add(each); } return result; }
/** * @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())); }
@Override public void setUp() { runner = new JUnitCore(); TestSystem system = new TestSystem(); results = system.outContents(); runner.addListener(new TextListener(system)); }
@Test public void constructor_is_called_for_each_test_in_test_class() throws Exception { // given JUnitCore jUnitCore = new JUnitCore(); jUnitCore.addListener(new TextListener(System.out)); // when jUnitCore.run(junit_test_with_3_tests_methods.class); // then assertThat(junit_test_with_3_tests_methods.constructor_instantiation).isEqualTo(3); }
@Test public void ensure_the_test_runner_breaks() throws Exception { JUnitCore runner = new JUnitCore(); runner.addListener(new TextListener(System.out)); Result result = runner.run(TestClassWithoutTestMethod.class); assertEquals(1, result.getFailureCount()); assertFalse(result.wasSuccessful()); }
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; }
public static void main(String... args) throws ClassNotFoundException { if (args.length != 2) { System.err.println("Usage: class method FIXME"); return; } String clazz = args[0]; String method = args[1]; Request request = Request.method(Class.forName(clazz), method); JUnitCore juc = new JUnitCore(); juc.addListener(new TextListener(new RealSystem())); Result result = juc.run(request); System.exit(0); }
@Override public TextListener get() { TextListener textListener = JUnit4RunnerBaseModule.provideTextListener(testRunnerOutSupplier.get()); assert textListener != null; return textListener; }
@Test public void test() { JUnitCore runner = new org.junit.runner.JUnitCore(); RunListener listener = new TextListener(System.out); runner.addListener(listener); Result result = runner.run(NotesRunnerTest.class); System.out.println("RESULT"); System.out.println(result); }
public static void run(final Class... suites) { boolean underTC = System.getenv(TEAMCITY_DETECT_VAR_NAME) != null; // prepare junit JUnitSystem system = new RealSystem(); JUnitCore core = new JUnitCore(); RunListener listener = underTC ? new TeamCityListener() : new TextListener(system); core.addListener(listener); int success = 0, failures = 0, ignores = 0; // run tests for (Class suite : suites) { sayNothing(); String suiteName = suite.getSimpleName(); if (suiteName.endsWith("Tests")) suiteName = suiteName.substring(0, suiteName.length()-"Tests".length()); if (suiteName.endsWith("Integration")) suiteName = suiteName.substring(0, suiteName.length()-"Integration".length()); if (suiteParameter != null) suiteName = suiteName + '[' + suiteParameter + ']'; if (underTC) say("##teamcity[testSuiteStarted name='%s']", suiteName); Result result = core.run(suite); success += result.getRunCount() - (result.getFailureCount() + result.getIgnoreCount()); failures += result.getFailureCount(); ignores += result.getIgnoreCount(); if (underTC) say("##teamcity[testSuiteFinished name='%s']", suiteName); sayNothing(); } }
public static void main(String[] args) { final JUnitCore core=new JUnitCore(); core.addListener(new TextListener(System.out)); core.run(RunnerHamcrestTest.class); }
public static void run(Class<?>[] testClasses, Result result) { JUnitCore jUnitCore = new JUnitCore(); jUnitCore.addListener(new TextListener(System.out)); jUnitCore.addListener(result.createListener()); jUnitCore.run(testClasses); }
@Override public String toString() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); new TextListener(new PrintStream(stream)).testRunFinished(result); return stream.toString(); }