Class JUnitMatchers
- Author:
- alexeagle@google.com (Alex Eagle), eaftan@google.com (Eddie Aftandillian)
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Matcher
<com.sun.source.tree.MethodTree> static final Matcher
<com.sun.source.tree.MethodTree> static final Matcher
<com.sun.source.tree.ClassTree> Match a class which has one or more methods with a JUnit 4 @Test annotation.static final MultiMatcher
<com.sun.source.tree.ClassTree, com.sun.source.tree.AnnotationTree> static final Matcher
<com.sun.source.tree.ClassTree> Matches classes which have attributes of both JUnit 3 and 4 classes.static final Matcher
<com.sun.source.tree.ClassTree> Match a class which appears to be missing a @RunWith annotation.static final Matcher
<com.sun.source.tree.MethodTree> Match a method which appears to be a JUnit 3 test case.static final Matcher
<com.sun.source.tree.ClassTree> Match a class which appears to be a JUnit 3 test class.static final Matcher
<com.sun.source.tree.ClassTree> Matches classes which have attributes of only JUnit4 test classes.static final Matcher
<com.sun.source.tree.ClassTree> Matches a class that inherits from TestCase.static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final Matcher
<com.sun.source.tree.MethodTree> Match a method which appears to be a JUnit 3 setUp methodstatic final Matcher
<com.sun.source.tree.MethodTree> Match a method which appears to be a JUnit 3 tearDown methodstatic final Matcher
<com.sun.source.tree.MethodTree> Matches a method which appears to be a JUnit4 @After method.static final Matcher
<com.sun.source.tree.MethodTree> Matches a method which appears to be a JUnit4 @Before method.static final Matcher
<com.sun.source.tree.MethodTree> Matches a JUnit 3 or 4 test case.static final Matcher
<com.sun.source.tree.MethodTree> Matches a method annotated with @Test but not @Ignore. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
containsTestMethod
(com.sun.source.tree.Tree tree) Returns true if the tree contains a method invocation that looks like a test assertion.static boolean
hasJUnitAnnotation
(com.sun.source.tree.MethodTree tree, VisitorState state) Checks if a method, or any overridden method, is annotated with any annotation from the org.junit package.static Matcher
<com.sun.source.tree.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
Matches a class that inherits from TestCase. -
isConcreteClassWithoutRunWith
Match a class which appears to be missing a @RunWith annotation.Matches if: 1) The class does not have a JUnit 4 @RunWith annotation. 2) The class is concrete. 3) The class is a top-level class.
-
hasJUnit4TestCases
Match a class which has one or more methods with a JUnit 4 @Test annotation. -
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
@RunWith
annotation 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
Before
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 -
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
After
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 -
wouldRunInJUnit4
Matches a method annotated with @Test but not @Ignore. -
TEST_CASE
Matches a JUnit 3 or 4 test case. -
hasJUnit4TestRunner
public static final MultiMatcher<com.sun.source.tree.ClassTree,com.sun.source.tree.AnnotationTree> 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@RunWith
or 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
isJUnit4TestClass
norisJUnit3TestClass
.
-
-
Method Details
-
hasJUnitAnnotation
Checks if a method, or any overridden method, is annotated with any annotation from the org.junit package. -
isJUnit4TestRunnerOfType
public static Matcher<com.sun.source.tree.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.TODO(eaftan): Support checking for an annotation that tells us whether this test runner expects tests to be annotated with @Test.
-
containsTestMethod
public static boolean containsTestMethod(com.sun.source.tree.Tree tree) Returns true if the tree contains a method invocation that looks like a test assertion.
-