Class JUnitMatchers
- 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 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 booleancontainsTestMethod(Tree tree) Returns true if the tree contains a method invocation that looks like a test assertion.static 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:
-
hasJUnit4BeforeAnnotations
-
hasJUnit4AfterAnnotations
-
isTestCaseDescendant
-
isConcreteClassWithoutRunWith
-
hasJUnit4TestCases
-
isJUnit3TestClass
Match a class which appears to be a JUnit 3 test class.Matches if: 1) The class does inherit from TestCase. 2) The class does not have a JUnit 4
@RunWithannotation nor any methods annotated@Test. 3) The class is concrete. 4) This class is a top-level class. -
isJunit3TestCase
Match a method which appears to be a JUnit 3 test case.Matches if: 1) The method's name begins with "test". 2) The method has no parameters. 3) The method is public. 4) The method returns void
-
looksLikeJUnit3SetUp
Match a method which appears to be a JUnit 3 setUp methodMatches if: 1) The method is named "setUp" 2) The method has no parameters 3) The method is a public or protected instance method that is not abstract 4) The method returns void
-
looksLikeJUnit4Before
Matches a method which appears to be a JUnit4 @Before method.Matches if: 1) The method is annotated
Before2) The method has no parameters 3) The method is a public or protected instance method that is not abstract 4) The method returns void -
looksLikeJUnit3TearDown
Match a method which appears to be a JUnit 3 tearDown methodMatches if: 1) The method is named "tearDown" 2) The method has no parameters 3) The method is a public or protected instance method that is not abstract 4) The method returns void
-
looksLikeJUnit4After
Matches a method which appears to be a JUnit4 @After method.Matches if: 1) The method is annotated
After2) The method has no parameters 3) The method is a public or protected instance method that is not abstract 4) The method returns void -
wouldRunInJUnit4
Matches a method annotated with @Test but not @Ignore. -
TEST_CASE
Matches a JUnit 3 or 4 test case. -
hasJUnit4TestRunner
-
isJUnit4TestClass
Matches classes which have attributes of only JUnit4 test classes.Matches if 1) the class is non-abstract, 2) the class does not inherit from JUnit3
TestCase, and 3) the class is annotated with@RunWithor any method therein is annotated with@Test. -
isAmbiguousJUnitVersion
Matches classes which have attributes of both JUnit 3 and 4 classes.Matches if the class 1) inherits from JUnit 3
TestCase, and 2) a) has a JUnit4 test runner annotation, or b) has any methods annotated@Test.As currently implemented, classes with ambiguous version will match neither
isJUnit4TestClassnorisJUnit3TestClass.
-
-
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.
-
containsTestMethod
Returns true if the tree contains a method invocation that looks like a test assertion.
-