org.junit.internal.runners.ErrorReportingRunner Java Examples

The following examples show how to use org.junit.internal.runners.ErrorReportingRunner. 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: ParameterisedJUnitTestFinder.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Override
public List<TestUnit> findTestUnits(final Class<?> clazz) {

  final Runner runner = AdaptedJUnitTestUnit.createRunner(clazz);
  if ((runner == null)
      || runner.getClass().isAssignableFrom(ErrorReportingRunner.class)) {
    return Collections.emptyList();
  }

  if (isParameterizedTest(runner)) {
    return handleParameterizedTest(clazz, runner.getDescription());
  }

  return Collections.emptyList();

}
 
Example #2
Source File: AndroidLogOnlyBuilderTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
public void builderHandlesNotATest() throws Throwable {
  Runner selectedRunner = androidLogOnlyBuilder.runnerForClass(NotATest.class);
  if (scanningPath) {
    assertThat(selectedRunner, nullValue());
  } else {
    assertThat(selectedRunner, notNullValue());
    assertThat(selectedRunner.getClass(), typeCompatibleWith(ErrorReportingRunner.class));
    runWithRunner(selectedRunner, 1, 1);
  }
}
 
Example #3
Source File: AdaptedJUnitTestUnit.java    From pitest with Apache License 2.0 5 votes vote down vote up
private void checkForErrorRunner(final Runner runner) {
  if (runner instanceof ErrorReportingRunner) {
    LOG.warning("JUnit error for class " + this.clazz + " : "
        + runner.getDescription());
  }

}
 
Example #4
Source File: JUnitCustomRunnerTestUnitFinder.java    From pitest with Apache License 2.0 5 votes vote down vote up
private boolean isNotARunnableTest(final Runner runner,
    final String className) {
  try {
    return (runner == null)
        || runner.getClass().isAssignableFrom(ErrorReportingRunner.class)
        || isParameterizedTest(runner)
        || isAJUnitThreeErrorOrWarning(runner)
        || isJUnitThreeSuiteMethodNotForOwnClass(runner, className);
  } catch (final RuntimeException ex) {
    // some runners (looking at you spock) can throw a runtime exception
    // when the getDescription method is called
    return true;
  }
}
 
Example #5
Source File: AndroidLogOnlyBuilder.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Override
public Runner runnerForClass(Class<?> testClass) throws Throwable {
  // Increment the number of runners created.
  ++runnerCount;

  // Build non executing runners for JUnit3 test classes
  if (isJUnit3Test(testClass)) {
    // If scanning the path then make sure that it has at least one test method before
    // trying to run it.
    if (scanningPath && !hasJUnit3TestMethod(testClass)) {
      return null;
    }

    return new JUnit38ClassRunner(new NonExecutingTestSuite(testClass));
  } else if (hasSuiteMethod(testClass)) {
    if (runnerParams.isIgnoreSuiteMethods()) {
      return null;
    }

    Test test = SuiteMethod.testFromSuiteMethod(testClass);
    if (!(test instanceof TestSuite)) {
      // this should not be possible
      throw new IllegalArgumentException(
          testClass.getName() + "#suite() did not return a TestSuite");
    }
    return new JUnit38ClassRunner(new NonExecutingTestSuite((TestSuite) test));
  } else {
    // Reset the count of the number of Runners created for the supplied testClass. Save
    // away the number created for the parent testClass.
    int oldRunnerCount = runnerCount;
    Runner runner = builder.runnerForClass(testClass);
    if (null == runner) {
      // If the runner could not be created then do not wrap it.
      return null;
    } else if (runner instanceof ErrorReportingRunner) {
      // Preserve behavior where a failure during construction results in an error,
      // even while in logOnly mode, by simply returning the runner rather than
      // wrapping it.
      return runner;
    } else if (runnerCount > oldRunnerCount) {
      // If constructing the testClass caused us to reenter here to build Runner
      // instances, e.g. for Suite or Enclosed, then this must not wrap runner in a
      // NonExecutingRunner as that would cause problems if any of the nested classes
      // were JUnit 3 ones.
      return runner;
    } else {
      return new NonExecutingRunner(runner);
    }
  }
}
 
Example #6
Source File: TestLoaderTest.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Test
public void testLoadTests_runWith() {
  // This fails because it has no @Test annotated methods.
  assertLoadTestSuccess(JUnit4RunTest.class, ErrorReportingRunner.class);
}
 
Example #7
Source File: TestLoaderTest.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Test
public void testLoadTests_all() {
  Collection<String> classNames =
      Arrays.asList(
          JUnit3Test.class.getName(),
          EmptyJUnit3Test.class.getName(),
          JUnit4Test.class.getName(),
          JUnit4RunTest.class.getName(),
          NotATest.class.getName(),
          CustomTest.class.getName(),
          "notexist",
          AbstractTest.class.getName(),
          SubClassJUnit4Test.class.getName(),
          SubClassAbstractTest.class.getName());

  List<Runner> runners = loader.getRunnersFor(classNames, false);
  List<Class<? extends Runner>> runnerClasses = new ArrayList<>();
  for (Runner runner : runners) {
    runnerClasses.add(runner == null ? null : runner.getClass());
  }

  List<Class<? extends Runner>> expectedRunnerClasses;
  if (scanningPath) {
    // When scanning path TestLoader is stricter about what it will accept as a test.
    expectedRunnerClasses =
        Arrays.asList(
            JUnit38ClassRunner.class,
            AndroidJUnit4ClassRunner.class,
            ErrorReportingRunner.class,
            UnloadableClassRunner.class,
            AndroidJUnit4ClassRunner.class,
            JUnit38ClassRunner.class);
  } else {
    expectedRunnerClasses =
        Arrays.asList(
            JUnit38ClassRunner.class,
            JUnit38ClassRunner.class,
            AndroidJUnit4ClassRunner.class,
            ErrorReportingRunner.class,
            ErrorReportingRunner.class,
            ErrorReportingRunner.class,
            UnloadableClassRunner.class,
            JUnit38ClassRunner.class,
            AndroidJUnit4ClassRunner.class,
            JUnit38ClassRunner.class);
  }
  assertEquals(expectedRunnerClasses, runnerClasses);
}
 
Example #8
Source File: TestLoaderTest.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Test
public void testLoadTests_notATest() {
  assertScanningLoadsAnyClass(NotATest.class, ErrorReportingRunner.class);
}
 
Example #9
Source File: TestLoaderTest.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Test
public void testLoadTests_CustomTest() {
  assertScanningLoadsAnyClass(CustomTest.class, ErrorReportingRunner.class);
}
 
Example #10
Source File: JUnit4Runner.java    From bazel with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"ThrowableInstanceNeverThrown"})
private static Request createErrorReportingRequestForFilterError(Filter filter) {
  ErrorReportingRunner runner = new ErrorReportingRunner(Filter.class, new Exception(
      String.format("No tests found matching %s", filter.describe())));
  return Request.runner(runner);
}