Back to Error Prone

JUnit4ClassAnnotationNonStatic

docs/bugpattern/JUnit4ClassAnnotationNonStatic.md

2.49.0684 B
Original Source

JUnit4 provides two annotations (@BeforeClass and @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.