Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

VisibleForTesting

class VisibleForTesting
androidx.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

Constants
static Int

The annotated element would have "private" visibility

static Int

The annotated element would have "package private" visibility

static Int

The annotated element would have "protected" visibility

static Int

The annotated element should never be called from production code, only from tests.

Public constructors
<init>(otherwise: Int)

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.

Properties
Int

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

Constants

PRIVATE

static val PRIVATE: Int

The annotated element would have "private" visibility

Value: 2

PACKAGE_PRIVATE

static val PACKAGE_PRIVATE: Int

The annotated element would have "package private" visibility

Value: 3

PROTECTED

static val PROTECTED: Int

The annotated element would have "protected" visibility

Value: 4

NONE

static val NONE: Int

The annotated element should never be called from production code, only from tests.

This is equivalent to @RestrictTo.Scope.TESTS.

Value: 5

Public constructors

<init>

VisibleForTesting(otherwise: Int)

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.

Properties

otherwise

val otherwise: Int

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