org.junit.internal.RealSystem Java Examples

The following examples show how to use org.junit.internal.RealSystem. 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: TestSuiteExecutor.java    From dekaf with Apache License 2.0 5 votes vote down vote up
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 #2
Source File: RtgTestEntry.java    From rtg-tools with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 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);
    }
  }
}