org.junit.internal.TextListener Java Examples
The following examples show how to use
org.junit.internal.TextListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRunner.java From marathonv5 with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: JUnit4RunnerTest.java From bazel with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: runAllTestCases.java From tuffylite with Apache License 2.0 | 6 votes |
/** * @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 ); }
Example #4
Source File: SquidbTestRunner.java From squidb with Apache License 2.0 | 5 votes |
/** * 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"); } }
Example #5
Source File: TestSuiteExecutor.java From dekaf with Apache License 2.0 | 5 votes |
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(); } }
Example #6
Source File: RunJUnit4TestsFromJava.java From tutorials with MIT License | 5 votes |
public static void runRepeatedSuite() { TestSuite mySuite = new ActiveTestSuite(); JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); mySuite.addTest(new RepeatedTest(new JUnit4TestAdapter(FirstUnitTest.class), 5)); mySuite.addTest(new RepeatedTest(new JUnit4TestAdapter(SecondUnitTest.class), 3)); junit.run(mySuite); }
Example #7
Source File: RunJUnit4TestsFromJava.java From tutorials with MIT License | 5 votes |
public static void runRepeated() { Test test = new JUnit4TestAdapter(SecondUnitTest.class); RepeatedTest repeatedTest = new RepeatedTest(test, 5); JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); junit.run(repeatedTest); }
Example #8
Source File: RunJUnit4TestsFromJava.java From tutorials with MIT License | 5 votes |
public static void runSuiteOfClasses() { JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); Result result = junit.run(MyTestSuite.class); for (Failure failure : result.getFailures()) { System.out.println(failure.toString()); } resultReport(result); }
Example #9
Source File: RunJUnit4TestsFromJava.java From tutorials with MIT License | 5 votes |
public static void runAllClasses() { JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); Result result = junit.run(FirstUnitTest.class, SecondUnitTest.class); for (Failure failure : result.getFailures()) { System.out.println(failure.toString()); } resultReport(result); }
Example #10
Source File: HashemTestRunner.java From mr-hashemi with Universal Permissive License v1.0 | 5 votes |
public static void runInMain(Class<?> testClass, String[] args) throws InitializationError, NoTestsRemainException { JUnitCore core = new JUnitCore(); core.addListener(new TextListener(System.out)); HashemTestRunner suite = new HashemTestRunner(testClass); if (args.length > 0) { suite.filter(new NameFilter(args[0])); } Result r = core.run(suite); if (!r.wasSuccessful()) { System.exit(1); } }
Example #11
Source File: ProvideTextListenerFactory.java From bazel with Apache License 2.0 | 5 votes |
@Override public TextListener get() { TextListener textListener = JUnit4RunnerBaseModule.provideTextListener(testRunnerOutSupplier.get()); assert textListener != null; return textListener; }
Example #12
Source File: GuidedFuzzing.java From JQF with BSD 2-Clause "Simplified" License | 5 votes |
/** * Runs the guided fuzzing loop for a resolved class. * * <p>The test class must be annotated with <tt>@RunWith(JQF.class)</tt> * and the test method must be annotated with <tt>@Fuzz</tt>.</p> * * <p>Once this method is invoked, the guided fuzzing loop runs continuously * until the guidance instance decides to stop by returning <tt>false</tt> * for {@link Guidance#hasInput()}. Until the fuzzing stops, this method * cannot be invoked again (i.e. at most one guided fuzzing can be running * at any time in a single JVM instance).</p> * * @param testClass the test class containing the test method * @param testMethod the test method to execute in the fuzzing loop * @param guidance the fuzzing guidance * @param out an output stream to log Junit messages * @throws IllegalStateException if a guided fuzzing run is currently executing * @return the Junit-style test result */ public synchronized static Result run(Class<?> testClass, String testMethod, Guidance guidance, PrintStream out) throws IllegalStateException { // Ensure that the class uses the right test runner RunWith annotation = testClass.getAnnotation(RunWith.class); if (annotation == null || !annotation.value().equals(JQF.class)) { throw new IllegalArgumentException(testClass.getName() + " is not annotated with @RunWith(JQF.class)"); } // Set the static guided instance setGuidance(guidance); // Register callback SingleSnoop.setCallbackGenerator(guidance::generateCallBack); // Create a JUnit Request Request testRequest = Request.method(testClass, testMethod); // Instantiate a runner (may return an error) Runner testRunner = testRequest.getRunner(); // Start tracing for the test method SingleSnoop.startSnooping(testClass.getName() + "#" + testMethod); // Run the test and make sure to de-register the guidance before returning try { JUnitCore junit = new JUnitCore(); if (out != null) { junit.addListener(new TextListener(out)); } return junit.run(testRunner); } finally { unsetGuidance(); } }
Example #13
Source File: GcjTestRunner.java From google-cloud-java with Apache License 2.0 | 5 votes |
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); }
Example #14
Source File: IntegrationTestsDriver.java From hbase with Apache License 2.0 | 5 votes |
@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; }
Example #15
Source File: JUnitTestRunner.java From j2objc with Apache License 2.0 | 5 votes |
/** * 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"); } }
Example #16
Source File: MethodTestRunner.java From astor with GNU General Public License v2.0 | 5 votes |
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(); } }
Example #17
Source File: MockitoRunnerBreaksWhenNoTestMethodsTest.java From astor with GNU General Public License v2.0 | 5 votes |
@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()); }
Example #18
Source File: MockInjectionUsingConstructorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@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); }
Example #19
Source File: MethodTestRunner.java From nopol with GNU General Public License v2.0 | 5 votes |
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(); } }
Example #20
Source File: JUnit4RunnerBaseModule.java From bazel with Apache License 2.0 | 4 votes |
static RunListener textListener(TextListener impl) { return impl; }
Example #21
Source File: JUnit4RunnerBaseModule.java From bazel with Apache License 2.0 | 4 votes |
@Singleton static TextListener provideTextListener(@Stdout PrintStream testRunnerOut) { return new TextListener(asUtf8PrintStream(testRunnerOut)); }
Example #22
Source File: TextListenerFactory.java From bazel with Apache License 2.0 | 4 votes |
public TextListenerFactory(Supplier<TextListener> implSupplier) { assert implSupplier != null; this.implSupplier = implSupplier; }
Example #23
Source File: TextListenerFactory.java From bazel with Apache License 2.0 | 4 votes |
public static Factory<RunListener> create(Supplier<TextListener> implSupplier) { return new TextListenerFactory(implSupplier); }
Example #24
Source File: ProvideTextListenerFactory.java From bazel with Apache License 2.0 | 4 votes |
public static Factory<TextListener> create(Supplier<PrintStream> testRunnerOutSupplier) { return new ProvideTextListenerFactory(testRunnerOutSupplier); }
Example #25
Source File: RunJUnit4TestsFromJava.java From tutorials with MIT License | 4 votes |
public static void runOne() { JUnitCore junit = new JUnitCore(); junit.addListener(new TextListener(System.out)); junit.run(FirstUnitTest.class); }
Example #26
Source File: InstrumentationResultPrinter.java From android-test with Apache License 2.0 | 4 votes |
@Override public void instrumentationRunFinished( PrintStream streamResult, Bundle resultBundle, Result junitResults) { // reuse JUnit TextListener to display a summary of the run new TextListener(streamResult).testRunFinished(junitResults); }
Example #27
Source File: RtgTestEntry.java From rtg-tools with BSD 2-Clause "Simplified" License | 4 votes |
/** * Test runner entry point * @param args list of test classes to run * @throws ClassNotFoundException can't load the specified classes */ @SuppressWarnings("unchecked") public static void main(final String[] args) throws ClassNotFoundException { final JUnitCore jUnitCore = new JUnitCore(); if (CAPTURE_OUTPUT) { jUnitCore.addListener(new OutputListener()); } jUnitCore.addListener(new TextListener(new RealSystem())); final TimingListener timing; if (COLLECT_TIMINGS) { timing = new TimingListener(); jUnitCore.addListener(timing); } else { timing = null; } if (PRINT_FAILURES) { jUnitCore.addListener(new FailureListener()); } if (PRINT_NAMES) { jUnitCore.addListener(new NameListener()); } jUnitCore.addListener(new NewLineListener()); final List<Result> results = new ArrayList<>(); if (args.length > 0) { for (final String arg : args) { final Class<?> klass = ClassLoader.getSystemClassLoader().loadClass(arg); results.add(jUnitCore.run(klass)); } } else { final Class<?>[] classes = getClasses(); results.add(jUnitCore.run(classes)); } if (timing != null) { final Map<String, Long> timings = timing.getTimings(LONG_TEST_THRESHOLD); if (timings.size() > 1) { System.out.println(); System.out.println("Long tests"); for (Map.Entry<String, Long> entry : timings.entrySet()) { System.out.println(formatTimeRow(entry.getKey(), entry.getValue(), TIMING_WIDTH)); } } } for (Result result : results) { if (!result.wasSuccessful()) { System.exit(1); } } }