下面列出了org.junit.internal.runners.ErrorReportingRunner#org.junit.internal.runners.SuiteMethod 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
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); }
}
@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);
}
}
}
private static Predicate<Description> isSuiteMethodRunner(final Runner runner) {
return a -> SuiteMethod.class.isAssignableFrom(runner.getClass());
}