== Why is this an issue?

@VisibleForTesting can be used to mark methods, fields and classes whose visibility restrictions have been relaxed more than necessary for the API to allow for easier unit testing.


Access to such methods, fields and classes only possible thanks to this relaxed visibility is fine for test code, but it should be avoided in production code. In production code these methods should be treated as if they are private.


Supported framework:

* Guava: ``++com.google.common.annotations.VisibleForTesting++``

* AssertJ: ``++org.assertj.core.util.VisibleForTesting++``

* Android: ``++androidx.annotation.VisibleForTesting++``

* Apache Flink: ``++org.apache.flink.annotation.VisibleForTesting++``

or any other annotation named ``++VisibleForTesting++``


=== Noncompliant code example

[source,java]
----
/** src/main/java/MyObject.java */

@VisibleForTesting String foo;

/** src/main/java/Service.java */

new MyObject().foo; // Noncompliant, foo is accessed from production code
----


=== Compliant solution

[source,java]
----
/** src/main/java/MyObject.java */

@VisibleForTesting String foo;

/** src/test/java/MyObjectTest.java */

new MyObject().foo; // Compliant, foo is accessed from test code
----

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::message.adoc[]

include::highlighting.adoc[]

endif::env-github,rspecator-view[]
