VisibleForTesting plugin for SonarQube
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

VisibleForTesting plugin for SonarQube

Build Status


This plugin for SonarQube allows developers to detect common mistakes with Guava's @VisibleForTesting annotation.

It detects illegal access of annotated members and methods as well as illegal use of guava's @VisibleForTesting annotation.

Unexpected access to @VisibleForTesting

Checks if production code accesses members or methods, that are annotated with @VisibleForTesting.

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.

Compliant code

/** src/main/java/ */
String foo;

/** src/test/java/ */
new MyObject().foo; // --> ok, accesses member from test code

Noncompliant code

/** src/main/java/ */
String foo;

/** src/main/java/ */
new MyObject().foo; // --> not ok, accesses member from production code

Misuse of @VisibleForTesting

Checks if @VisibleForTesting is only used on members or methods with default visibility, as its purpose is to mark an increased visibility from private to default.

Compliant code

String foo;

Noncompliant code

private String foo;

protected String foo;

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\plugins folder 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