VisibleForTesting
-
Cmn
@MustBeDocumented
@Retention(value = AnnotationRetention.BINARY)
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 |
||
|---|---|---|
const Int |
NONE = 5The annotated element should never be called from production code, only from tests. |
Cmn
|
const Int |
PACKAGE_PRIVATE = 3The annotated element would have |
Cmn
|
const Int |
PRIVATE = 2The annotated element would have |
Cmn
|
const Int |
PROTECTED = 4The annotated element would have |
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.