File: JUnit4ClassAnnotationNonStatic.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 (11 lines) | stat: -rw-r--r-- 683 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
JUnit4 provides two annotations ([`@BeforeClass`][beforeclass] and
[`@AfterClass`][afterclass]) that are applied to methods that are run once per
**test class**. These complement the more-often used `@Before` and `@After`
which are applied to methods that are run once per **test method**.

JUnit4 runs `@BeforeClass` and `@AfterClass` methods without making an instance
of the test class, meaning that the methods must be `static`. JUnit4 will fail
to run any `@BeforeClass` or `@AfterClass` method that isn't also `static`.

[beforeclass]: http://junit.sourceforge.net/javadoc/org/junit/BeforeClass.html
[afterclass]: http://junit.sourceforge.net/javadoc/org/junit/AfterClass.html