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

const Int
NONE = 5

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

Cmn
const Int

The annotated element would have package private visibility.

Cmn
const Int

The annotated element would have private visibility.

Cmn
const Int

The annotated element would have protected visibility.

Cmn

Public constructors

VisibleForTesting(otherwise: Int)
Cmn

Public properties

Int

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

Cmn

Constants

NONE

const val NONE = 5: Int

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

This is equivalent to RestrictTo.Scope.TESTS.

PACKAGE_PRIVATE

const val PACKAGE_PRIVATE = 3: Int

The annotated element would have package private visibility.

PRIVATE

const val PRIVATE = 2: Int

The annotated element would have private visibility.

PROTECTED

const val PROTECTED = 4: Int

The annotated element would have protected visibility.

Public constructors

VisibleForTesting

VisibleForTesting(otherwise: Int = PRIVATE)

Public properties

otherwise

val otherwiseInt

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