org.junit.internal.runners.SuiteMethod Java Examples

The following examples show how to use org.junit.internal.runners.SuiteMethod. 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: AndroidSuiteBuilder.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Override
public Runner runnerForClass(Class<?> testClass) throws Throwable {
  if (androidRunnerParams.isIgnoreSuiteMethods()) {
    return null;
  }
  try {
    if (hasSuiteMethod(testClass)) {
      Test t = SuiteMethod.testFromSuiteMethod(testClass);
      if (!(t instanceof TestSuite)) {
        // this should not be possible
        throw new IllegalArgumentException(
            testClass.getName() + "#suite() did not return a TestSuite");
      }
      return new JUnit38ClassRunner(new AndroidTestSuite((TestSuite) t, androidRunnerParams));
    }
  } catch (Throwable e) {
    // log error message including stack trace before throwing to help with debugging.
    Log.e(LOG_TAG, "Error constructing runner", e);
    throw e;
  }
  return null;
}
 
Example #2
Source File: AllTestsJUnit4Runner.java    From beanshell with Apache License 2.0 5 votes vote down vote up
public AllTestsJUnit4Runner(Class<?> klass) throws InitializationError {
    super(klass);
    try {
        suite = (TestSuite) SuiteMethod.testFromSuiteMethod(klass);
        method = TestCase.class.getDeclaredMethod("runBare");
    } catch (Throwable t) { throw new InitializationError(t); }

}
 
Example #3
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 #4
Source File: RunnerSuiteFinder.java    From pitest with Apache License 2.0 4 votes vote down vote up
private static Predicate<Description> isSuiteMethodRunner(final Runner runner) {
  return a -> SuiteMethod.class.isAssignableFrom(runner.getClass());
}