Stay organized with collections Save and categorize content based on your preferences.

VisibleForTesting

@Retention(value = AnnotationRetention.BINARY)
public annotation VisibleForTesting


Denotes that the class, method or field has its visibility relaxed, so that it is more widely visible than otherwise necessary to make code testable.

You can optionally specify what the visibility should have been if not for testing; this allows tools to catch unintended access from within production code.

Example:

@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
public String printDiagnostics() { ... }

If not specified, the intended visibility is assumed to be private.

Summary

Public fields

final int

The visibility the annotated element would have if it did not need to be made visible for testing.

Public constructors

VisibleForTesting(int otherwise)

Public fields

otherwise

public final int otherwise

The visibility the annotated element would have if it did not need to be made visible for testing.

Public constructors

VisibleForTesting

public final VisibleForTesting(int otherwise)