Test (@NotNull final Class<?> testCaseClass) { try { if ((testCaseClass.getModifiers() & Modifier.PUBLIC) == 0) { return null; } Bombed classBomb = testCaseClass.getAnnotation(Bombed.class); if (classBomb != null && TestFrameworkUtil.bombExplodes(classBomb)) { return new ExplodedBomb(testCaseClass.getName(), classBomb); } Method suiteMethod = safeFindMethod(testCaseClass, "suite"); if (suiteMethod != null && !isPerformanceTestsRun()) { return (Test)suiteMethod.invoke(null, ArrayUtilRt.EMPTY_OBJECT_ARRAY); } if (TestFrameworkUtil.isJUnit4TestClass(testCaseClass, false)) { boolean isPerformanceTest = isPerformanceTest(null, testCaseClass.getSimpleName()); boolean runEverything = isIncludingPerformanceTestsRun() || isPerformanceTest && isPerformanceTestsRun(); if (runEverything) return createJUnit4Adapter(testCaseClass); final RunWith runWithAnnotation = testCaseClass.getAnnotation(RunWith.class); if (runWithAnnotation != null && Parameterized.class.isAssignableFrom(runWithAnnotation.value())) { if (isPerformanceTestsRun() != isPerformanceTest) { // do not create JUnit4TestAdapter for @Parameterized tests to avoid @Parameters computation - just skip the test return null; } else { return createJUnit4Adapter(testCaseClass); } } JUnit4TestAdapter adapter = createJUnit4Adapter(testCaseClass); try { adapter.filter(NOT_BOMBED.intersect(NOT_IGNORED).intersect(isPerformanceTestsRun() ? PERFORMANCE_ONLY : NO_PERFORMANCE)); } catch (NoTestsRemainException ignored) { } return adapter; } final int[] testsCount = {0}; TestSuite suite = new TestSuite(testCaseClass) { @Override public void addTest(Test test) { if (!(test instanceof TestCase)) { doAddTest(test); } else { String name = ((TestCase)test).getName(); if ("warning".equals(name)) return; // Mute TestSuite's "no tests found" warning if (!isIncludingPerformanceTestsRun() && (isPerformanceTestsRun() ^ isPerformanceTest(name, testCaseClass.getSimpleName()))) { return; } Method method = findTestMethod((TestCase)test); if (method != null && method.getAnnotation(IgnoreJUnit3.class) != null) { return; } Bombed methodBomb = method == null ? null : method.getAnnotation(Bombed.class); if (methodBomb == null) { doAddTest(test); } else if (TestFrameworkUtil.bombExplodes(methodBomb)) { doAddTest(new ExplodedBomb(method.getDeclaringClass().getName() + "." + method.getName(), methodBomb)); } } } private void doAddTest(Test test) { testsCount[0]++; super.addTest(test); } @Nullable private static Method findTestMethod(final TestCase testCase) { return safeFindMethod(testCase.getClass(), testCase.getName()); } }; return testsCount[0] > 0 ? suite : null; } catch (Throwable t) { System.err.println("Failed to load test: " + testCaseClass.getName()); t.printStackTrace(System.err); return null; } }