google / google/error-prone

Disallow annotating a non-static method with @BeforeClass

Open
#25 11 comments 0 reactions 0 assignees View on GitHub
migrated Priority-High Status-Accepted Type-NewCheck
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

_[Original issue](https://code.google.com/p/error-prone/issues/detail?id=25) created by **eaftan@google.com** on 2012-07-16 at 07:18 PM_

---

The JUnit @BeforeClass annotation should only be applied to a public static void no-arg method, otherwise it throws a runtime error. We should detect this at compile time.

There may also be other JUnit-specific checks we can write. For example, JUnit doesn't run tests that are not marked public. This can cause someone to mistakenly think that their newly created tests are runnign when they're actually not. Some other reason tests weren't being run:
- The test class did not extend TestCase
- The test method wasn't public
- The test method didn't start with "test" (e.g. tesSomething)
- The test method took a parameter

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.