Class JUnitMatchers
java.lang.Object
com.google.errorprone.matchers.JUnitMatchers
Matchers for code patterns which appear to be JUnit-based tests.
- Author:
- alexeagle@google.com (Alex Eagle), eaftan@google.com (Eddie Aftandillian)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Matcher<MethodTree> static final Matcher<MethodTree> Match a class which has one or more methods with a JUnit 4 @Test annotation.static final MultiMatcher<ClassTree, AnnotationTree> Matches classes which have attributes of both JUnit 3 and 4 classes.Match a class which appears to be missing a @RunWith annotation.static final Matcher<MethodTree> Match a method which appears to be a JUnit 3 test case.Match a class which appears to be a JUnit 3 test class.Matches classes which have attributes of only JUnit4 test classes.Matches a class that inherits from TestCase.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Matcher<MethodTree> Matches a JUnit 5 (Jupiter) lifecycle method, i.e. a setup or teardown method.static final Matcher<MethodTree> Matches a JUnit 5 (Jupiter) test method.static final Matcher<MethodTree> Matches a JUnit 5 (Jupiter) method that is invoked reflectively.static final Matcher<MethodTree> Match a method which appears to be a JUnit 3 setUp methodstatic final Matcher<MethodTree> Match a method which appears to be a JUnit 3 tearDown methodstatic final Matcher<MethodTree> Matches a method which appears to be a JUnit4 @After method.static final Matcher<MethodTree> Matches a method which appears to be a JUnit4 @Before method.static final Matcher<MethodTree> Matches a JUnit 3 or 4 test case.static final Matcher<MethodTree> Matches a method annotated with @Test but not @Ignore. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanhasJUnitAnnotation(MethodTree tree, VisitorState state) Checks if a method, or any overridden method, is annotated with any annotation from the org.junit package.static Matcher<ExpressionTree> isJUnit4TestRunnerOfType(Iterable<String> runnerTypes) Matches an argument of typeClass<T>, where T is a subtype of one of the test runners listed in the TEST_RUNNERS field.
-
Field Details
-
JUNIT4_TEST_ANNOTATION
- See Also:
-
JUNIT4_THEORY_ANNOTATION
- See Also:
-
JUNIT_BEFORE_ANNOTATION
- See Also:
-
JUNIT_AFTER_ANNOTATION
- See Also:
-
JUNIT_BEFORE_CLASS_ANNOTATION
- See Also:
-
JUNIT_AFTER_CLASS_ANNOTATION
- See Also:
-
JUNIT4_RUN_WITH_ANNOTATION
- See Also:
-
JUNIT4_ASSERT_CLASS
- See Also:
-
JUNIT3_TEST_CASE_CLASS
- See Also:
-
JUNIT4_IGNORE_ANNOTATION
- See Also:
-
JUNIT4_RUNNER_CLASS
- See Also:
-
JUNIT3_ASSERT_CLASS
- See Also:
-
hasJUnit4BeforeAnnotations
-
hasJUnit4AfterAnnotations
-
isTestCaseDescendant
-
isConcreteClassWithoutRunWith
-
hasJUnit4TestCases
-
isJUnit3TestClass
Match a class which appears to be a JUnit 3 test class.Matches if:
- The class does inherit from TestCase.
- The class does not have a JUnit 4
@RunWithannotation nor any methods annotated@Test. - The class is concrete.
- This class is a top-level class.
-
isJunit3TestCase
Match a method which appears to be a JUnit 3 test case.Matches if:
- The method's name begins with "test".
- The method has no parameters.
- The method is public.
- The method returns void.
-
looksLikeJUnit3SetUp
Match a method which appears to be a JUnit 3 setUp methodMatches if:
- The method is named "setUp".
- The method has no parameters.
- The method is a public or protected instance method that is not abstract.
- The method returns void.
-
looksLikeJUnit4Before
Matches a method which appears to be a JUnit4 @Before method.Matches if:
- The method is annotated
Before. - The method has no parameters.
- The method is a public or protected instance method that is not abstract.
- The method returns void.
- The method is annotated
-
looksLikeJUnit3TearDown
Match a method which appears to be a JUnit 3 tearDown methodMatches if:
- The method is named "tearDown".
- The method has no parameters.
- The method is a public or protected instance method that is not abstract.
- The method returns void.
-
looksLikeJUnit4After
Matches a method which appears to be a JUnit4 @After method.Matches if:
- The method is annotated
After. - The method has no parameters.
- The method is a public or protected instance method that is not abstract.
- The method returns void.
- The method is annotated
-
wouldRunInJUnit4
Matches a method annotated with @Test but not @Ignore. -
TEST_CASE
Matches a JUnit 3 or 4 test case. -
JUNIT5_TEST_METHOD
Matches a JUnit 5 (Jupiter) test method. -
JUNIT5_LIFECYCLE_METHOD
Matches a JUnit 5 (Jupiter) lifecycle method, i.e. a setup or teardown method. -
JUNIT5_TEST_OR_LIFECYCLE_METHOD
Matches a JUnit 5 (Jupiter) method that is invoked reflectively.Unlike
TEST_CASEthis also covers lifecycle methods, as Jupiter permits those to declare parameters. -
hasJUnit4TestRunner
-
isJUnit4TestClass
-
isAmbiguousJUnitVersion
Matches classes which have attributes of both JUnit 3 and 4 classes.Matches if the class:
- Inherits from JUnit 3
TestCase. -
- Has a JUnit4 test runner annotation, or
- Has any methods annotated
@Test.
As currently implemented, classes with ambiguous version will match neither
isJUnit4TestClassnorisJUnit3TestClass. - Inherits from JUnit 3
-
-
Method Details
-
hasJUnitAnnotation
Checks if a method, or any overridden method, is annotated with any annotation from the org.junit package. -
isJUnit4TestRunnerOfType
Matches an argument of typeClass<T>, where T is a subtype of one of the test runners listed in the TEST_RUNNERS field.TODO(eaftan): Support checking for an annotation that tells us whether this test runner expects tests to be annotated with @Test.
-