File: JUnitAmbiguousTestClass.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (17 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
For JUnit3-style tests, behavior is defined in `junit.framework.TestCase` and
tests add behavior by overriding methods. For JUnit4-style tests, special
behavior happens with fields and methods annotated with JUnit 4 annotations.
Having JUnit4-style tests extend from `junit.framework.TestCase` (directly or
indirectly) historically has been a source of test bugs and unexpected behavior
(e.g.: teardown logic and/or verification does not run because JUnit doesn't
call the inherited code).

Error Prone also cannot infer whether the test class runs with JUnit 3 or JUnit
4.

Thus, even if the test class runs with JUnit 4, Error Prone will not run
additional checks which can catch common errors with JUnit 4 test classes.
Either use only JUnit4 classes and annotations and remove the inheritance from
TestCase, or use only JUnit 3 and remove the `@Test` annotations. When looking
for replacements for base test classes, consider using Rules (see the `@Rule`
annotation and implementations of `TestRule` and `MethodRule`).