{"record":{"id":"da5ed32f1d0f1cff","repo":"google/guava","slug":"unable-to-extract-method-from-test-not-a-testcase","errorCode":null,"errorMessage":"unable to extract method from test: not a TestCase.","messagePattern":"unable to extract method from test: not a TestCase\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"android/guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java","lineNumber":275,"sourceCode":"      }\n      return false;\n    }\n    return true;\n  }\n\n  private static boolean intersect(Set<?> a, Set<?> b) {\n    return !disjoint(a, b);\n  }\n\n  private static Method extractMethod(Test test) {\n    if (test instanceof AbstractTester) {\n      AbstractTester<?> tester = (AbstractTester<?>) test;\n      return getMethod(tester.getClass(), tester.getTestMethodName());\n    } else if (test instanceof TestCase) {\n      TestCase testCase = (TestCase) test;\n      return getMethod(testCase.getClass(), testCase.getName());\n    } else {\n      throw new IllegalArgumentException(\"unable to extract method from test: not a TestCase.\");\n    }\n  }\n\n  protected TestSuite makeSuiteForTesterClass(Class<? extends AbstractTester<?>> testerClass) {\n    TestSuite candidateTests = new TestSuite(testerClass);\n    TestSuite suite = filterSuite(candidateTests);\n\n    Enumeration<?> allTests = suite.tests();\n    while (allTests.hasMoreElements()) {\n      Object test = allTests.nextElement();\n      if (test instanceof AbstractTester) {\n        @SuppressWarnings(\"unchecked\")\n        AbstractTester<? super G> tester = (AbstractTester<? super G>) test;\n        tester.init(subjectGenerator, name, setUp, tearDown);\n      }\n    }\n\n    return suite;","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/google/guava/blob/94f39958baf7ad51ddf9c70e406ed6b188194daa/android/guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java#L257-L293","documentation":"Thrown by FeatureSpecificTestSuiteBuilder.extractMethod(Test) when the given Test is neither an AbstractTester (which exposes getTestMethodName()) nor a junit TestCase (which exposes getName()). The library needs a reflective Method to read tester annotations and filter tests, so an unrecognized Test type cannot be processed.","triggerScenarios":"A custom Test object (e.g. a TestSuite wrapper, a junit 4-style runner, or a plain Runnable adapted to Test) reaches extractMethod via the matches()/filtering path inside makeSuiteForTesterClass. It is not an AbstractTester or TestCase subclass.","commonSituations":"Mixing junit 4/5 test styles with the guava-testlib junit 3 TestCase model; wrapping tester classes in a custom suite/decorator that changes the runtime Test type; providing a third-party Test implementation as a tester.","solutions":["Make sure every test added to the builder's tester suites is a subclass of AbstractTester (preferred) or junit.framework.TestCase.","Avoid wrapping tester instances in custom Test adapters; add the raw AbstractTester subclass via the builder's getTesters() list instead.","If you must filter, use the builder's .suppress(...) / feature-filtering mechanisms rather than replacing the Test objects."],"exampleFix":"// before\nclass MyDecorator implements Test { /* wraps an AbstractTester */ }\nsuite.addTest(new MyDecorator(tester));\n\n// after\n// Add the AbstractTester subclass directly; let the builder build the suite.\npublic class MyListAddTester extends AbstractListTester { public void testAdd() { ... } }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Only feed the builder tester classes that are AbstractTester/TestCase subclasses.\nstatic boolean isAcceptableTester(Class<?> c) {\n  return AbstractTester.class.isAssignableFrom(c) || junit.framework.TestCase.class.isAssignableFrom(c);\n}","tryCatchPattern":null,"preventionTips":["Never wrap tester instances in custom Test adapters; register the AbstractTester subclass in getTesters().","Avoid mixing junit 4/5 runners with the guava-testlib junit 3 model."],"tags":["guava-testlib","junit","reflection","test-filtering"],"backgroundTag":null,"analyzedSha":"94f39958baf7ad51ddf9c70e406ed6b188194daa","analyzedAt":"2026-08-13T22:50:30.265Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}