类org.junit.internal.TextListener源码实例Demo

下面列出了怎么用org.junit.internal.TextListener的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: marathonv5   文件: TestRunner.java
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;
}
 
源代码2 项目: tuffylite   文件: runAllTestCases.java
/**
	 * @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
		);

	}
 
源代码3 项目: bazel   文件: JUnit4RunnerTest.java
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;
}
 
源代码4 项目: mr-hashemi   文件: HashemTestRunner.java
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);
    }
}
 
源代码5 项目: JQF   文件: GuidedFuzzing.java
/**
 * 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();
    }



}
 
源代码6 项目: nopol   文件: MethodTestRunner.java
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();
    }
}
 
源代码7 项目: squidb   文件: SquidbTestRunner.java
/**
 * 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");
    }
}
 
源代码8 项目: astor   文件: MockInjectionUsingConstructorTest.java
@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());
}
 
源代码10 项目: astor   文件: MethodTestRunner.java
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();
	}
}
 
源代码11 项目: j2objc   文件: JUnitTestRunner.java
/**
 * 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");
  }
}
 
源代码12 项目: hbase   文件: IntegrationTestsDriver.java
@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;
}
 
源代码13 项目: google-cloud-java   文件: GcjTestRunner.java
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);
}
 
源代码14 项目: bazel   文件: ProvideTextListenerFactory.java
@Override
public TextListener get() {
  TextListener textListener =
      JUnit4RunnerBaseModule.provideTextListener(testRunnerOutSupplier.get());
  assert textListener != null;
  return textListener;
}
 
源代码15 项目: tutorials   文件: RunJUnit4TestsFromJava.java
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);
}
 
源代码16 项目: tutorials   文件: RunJUnit4TestsFromJava.java
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);
}
 
源代码17 项目: tutorials   文件: RunJUnit4TestsFromJava.java
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);
}
 
源代码18 项目: tutorials   文件: RunJUnit4TestsFromJava.java
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);
}
 
源代码19 项目: dekaf   文件: TestSuiteExecutor.java
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();
    }
  }
 
源代码20 项目: rtg-tools   文件: RtgTestEntry.java
/**
 * 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);
    }
  }
}
 
@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);
}
 
源代码22 项目: bazel   文件: JUnit4RunnerBaseModule.java
static RunListener textListener(TextListener impl) {
  return impl;
}
 
源代码23 项目: bazel   文件: JUnit4RunnerBaseModule.java
@Singleton
static TextListener provideTextListener(@Stdout PrintStream testRunnerOut) {
  return new TextListener(asUtf8PrintStream(testRunnerOut));
}
 
源代码24 项目: bazel   文件: TextListenerFactory.java
public TextListenerFactory(Supplier<TextListener> implSupplier) {
  assert implSupplier != null;
  this.implSupplier = implSupplier;
}
 
源代码25 项目: bazel   文件: TextListenerFactory.java
public static Factory<RunListener> create(Supplier<TextListener> implSupplier) {
  return new TextListenerFactory(implSupplier);
}
 
源代码26 项目: bazel   文件: ProvideTextListenerFactory.java
public static Factory<TextListener> create(Supplier<PrintStream> testRunnerOutSupplier) {
  return new ProvideTextListenerFactory(testRunnerOutSupplier);
}
 
源代码27 项目: tutorials   文件: RunJUnit4TestsFromJava.java
public static void runOne() {
    JUnitCore junit = new JUnitCore();
    junit.addListener(new TextListener(System.out));
    junit.run(FirstUnitTest.class);
}
 
 类所在包
 同包方法