Skip to content

Commit 8d4c117

Browse files
klueverError Prone Team
authored andcommitted
JUnit3 test methods in fact _can_ be static (and will still get run by the test runner!).
PiperOrigin-RevId: 914692547
1 parent 80b3101 commit 8d4c117

2 files changed

Lines changed: 1 addition & 11 deletions

File tree

check_api/src/main/java/com/google/errorprone/matchers/JUnitMatchers.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ private static boolean hasJUnitAttr(MethodSymbol methodSym) {
155155
* <li>The method's name begins with "test".
156156
* <li>The method has no parameters.
157157
* <li>The method is public.
158-
* <li>The method is not static.
159158
* <li>The method returns void.
160159
* </ol>
161160
*/
@@ -164,7 +163,6 @@ private static boolean hasJUnitAttr(MethodSymbol methodSym) {
164163
methodNameStartsWith("test"),
165164
methodHasNoParameters(),
166165
Matchers.<MethodTree>hasModifier(Modifier.PUBLIC),
167-
not(Matchers.<MethodTree>hasModifier(Modifier.STATIC)),
168166
methodReturns(VOID_TYPE));
169167

170168
/** Common matcher for possible JUnit setUp/tearDown methods. */

core/src/test/java/com/google/errorprone/bugpatterns/JUnit3TestNotRunTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,7 @@ public class KansasGlobalMetadataUtilsTest extends TestCase {
215215
public static void testParseGlobalMetadata() {}
216216
}
217217
""")
218-
.addOutputLines(
219-
"out/KansasGlobalMetadataUtilsTest.java",
220-
"""
221-
import junit.framework.TestCase;
222-
223-
public class KansasGlobalMetadataUtilsTest extends TestCase {
224-
public void testParseGlobalMetadata() {}
225-
}
226-
""")
218+
.expectUnchanged()
227219
.doTest();
228220
}
229221

0 commit comments

Comments
 (0)