VisibleForTesting plugin for SonarQube
It detects illegal access of annotated members and methods as well as illegal use of guava's
Unexpected access to @VisibleForTesting
Checks if production code accesses members or methods, that are annotated with
The annotation's goal is to mark members or methods, whose visibility is increased from
private to default only for testing purposes. If production code acesses those members or methods, this may lead to unexpected behaviours.
/** src/main/java/MyObject.java */ @VisibleForTesting String foo; /** src/test/java/MyObjectTest.java */ new MyObject().foo; // --> ok, accesses member from test code
/** src/main/java/MyObject.java */ @VisibleForTesting String foo; /** src/main/java/Service.java */ new MyObject().foo; // --> not ok, accesses member from production code
Misuse of @VisibleForTesting
@VisibleForTesting is only used on members or methods with default visibility, as its purpose is to mark an increased visibility from
private to default.
@VisibleForTesting String foo;
@VisibleForTesting private String foo; @VisibleForTesting protected String foo; @VisibleForTesting public String foo;
- SonarQube 6+ (maybe below but not tested)
- Java 8
- Download the latest release's plugin jar and put it into the
extensions\pluginsfolder of your SonarQube instance.
- Restart SonarQube.
- Add the rules to your quality profile.
- SonarQube 6 compatibility
- fixed some administrative properties in the POM file
- Initial release