public
abstract
@interface
VisibleForTesting
implements
Annotation
android.support.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.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# VisibleForTesting\n\nSummary: [Constants](#constants) \\| [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \\| [\\[Expand All\\]](#) \n\nVisibleForTesting\n=================\n\n| This package is part of the Android [support library](/topic/libraries/support-library) which is no longer maintained. The support library has been superseded by [AndroidX](/jetpack/androidx) which is part of [Jetpack](/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider [migrating](/jetpack/androidx/migrate) existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library [class\n| mappings](/jetpack/androidx/migrate/class-mappings).\n\n\n`\npublic\n\n\nabstract\n@interface\nVisibleForTesting\n`\n\n\n`\n\n\nimplements\n\nAnnotation\n\n\n`\n\n|----------------------------------------------|\n| android.support.annotation.VisibleForTesting |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nDenotes that the class, method or field has its visibility relaxed, so that it is more widely\nvisible than otherwise necessary to make code testable.\n\n\nYou can optionally specify what the visibility **should** have been if not for\ntesting; this allows tools to catch unintended access from within production\ncode.\n\n\nExample: \n\n\n @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)\n public String printDiagnostics() { ... }\n \nIf not specified, the intended visibility is assumed to be private.\n\n\u003cbr /\u003e\n\nSummary\n-------\n\n| ### Constants ||\n|-------|----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `int` | [NONE](/reference/android/support/annotation/VisibleForTesting#NONE) The annotated element should never be called from production code, only from tests. |\n| `int` | [PACKAGE_PRIVATE](/reference/android/support/annotation/VisibleForTesting#PACKAGE_PRIVATE) The annotated element would have \"package private\" visibility |\n| `int` | [PRIVATE](/reference/android/support/annotation/VisibleForTesting#PRIVATE) The annotated element would have \"private\" visibility |\n| `int` | [PROTECTED](/reference/android/support/annotation/VisibleForTesting#PROTECTED) The annotated element would have \"protected\" visibility |\n\n| ### Public methods ||\n|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` int` | ` `[otherwise](/reference/android/support/annotation/VisibleForTesting#otherwise())`() ` The visibility the annotated element would have if it did not need to be made visible for testing. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From interface ` java.lang.annotation.Annotation ` |-----------------------------------------|-------------------------| | ` abstract Class\u003c? extends Annotation\u003e` | ` annotationType() ` | | ` abstract boolean` | ` equals(Object arg0) ` | | ` abstract int` | ` hashCode() ` | | ` abstract String` | ` toString() ` | ||\n\nConstants\n---------\n\n### NONE\n\n```\nint NONE\n```\n\nThe annotated element should never be called from production code, only from tests.\n\n\nThis is equivalent to `@RestrictTo.Scope.TESTS`.\n\n\u003cbr /\u003e\n\nConstant Value:\n\n5\n(0x00000005)\n\n\n### PACKAGE_PRIVATE\n\n```\nint PACKAGE_PRIVATE\n```\n\nThe annotated element would have \"package private\" visibility\n\n\u003cbr /\u003e\n\nConstant Value:\n\n3\n(0x00000003)\n\n\n### PRIVATE\n\n```\nint PRIVATE\n```\n\nThe annotated element would have \"private\" visibility\n\n\u003cbr /\u003e\n\nConstant Value:\n\n2\n(0x00000002)\n\n\n### PROTECTED\n\n```\nint PROTECTED\n```\n\nThe annotated element would have \"protected\" visibility\n\n\u003cbr /\u003e\n\nConstant Value:\n\n4\n(0x00000004)\n\n\nPublic methods\n--------------\n\n### otherwise\n\n```\nint otherwise ()\n```\n\nThe visibility the annotated element would have if it did not need to be made visible for\ntesting.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-------|--------|\n| `int` | \u003cbr /\u003e |\n\n-\n\n Annotations\n -----------\n\n - [AnimatorRes](/reference/android/support/annotation/AnimatorRes)\n - [AnimRes](/reference/android/support/annotation/AnimRes)\n - [AnyRes](/reference/android/support/annotation/AnyRes)\n - [AnyThread](/reference/android/support/annotation/AnyThread)\n - [ArrayRes](/reference/android/support/annotation/ArrayRes)\n - [AttrRes](/reference/android/support/annotation/AttrRes)\n - [BinderThread](/reference/android/support/annotation/BinderThread)\n - [BoolRes](/reference/android/support/annotation/BoolRes)\n - [CallSuper](/reference/android/support/annotation/CallSuper)\n - [CheckResult](/reference/android/support/annotation/CheckResult)\n - [ColorInt](/reference/android/support/annotation/ColorInt)\n - [ColorLong](/reference/android/support/annotation/ColorLong)\n - [ColorRes](/reference/android/support/annotation/ColorRes)\n - [DimenRes](/reference/android/support/annotation/DimenRes)\n - [Dimension](/reference/android/support/annotation/Dimension)\n - [DrawableRes](/reference/android/support/annotation/DrawableRes)\n - [FloatRange](/reference/android/support/annotation/FloatRange)\n - [FontRes](/reference/android/support/annotation/FontRes)\n - [FractionRes](/reference/android/support/annotation/FractionRes)\n - [GuardedBy](/reference/android/support/annotation/GuardedBy)\n - [HalfFloat](/reference/android/support/annotation/HalfFloat)\n - [IdRes](/reference/android/support/annotation/IdRes)\n - [IntDef](/reference/android/support/annotation/IntDef)\n - [IntegerRes](/reference/android/support/annotation/IntegerRes)\n - [InterpolatorRes](/reference/android/support/annotation/InterpolatorRes)\n - [IntRange](/reference/android/support/annotation/IntRange)\n - [Keep](/reference/android/support/annotation/Keep)\n - [LayoutRes](/reference/android/support/annotation/LayoutRes)\n - [LongDef](/reference/android/support/annotation/LongDef)\n - [MainThread](/reference/android/support/annotation/MainThread)\n - [MenuRes](/reference/android/support/annotation/MenuRes)\n - [NavigationRes](/reference/android/support/annotation/NavigationRes)\n - [NonNull](/reference/android/support/annotation/NonNull)\n - [Nullable](/reference/android/support/annotation/Nullable)\n - [PluralsRes](/reference/android/support/annotation/PluralsRes)\n - [Px](/reference/android/support/annotation/Px)\n - [RawRes](/reference/android/support/annotation/RawRes)\n - [RequiresApi](/reference/android/support/annotation/RequiresApi)\n - [RequiresPermission](/reference/android/support/annotation/RequiresPermission)\n - [RequiresPermission.Read](/reference/android/support/annotation/RequiresPermission.Read)\n - [RequiresPermission.Write](/reference/android/support/annotation/RequiresPermission.Write)\n - [RestrictTo](/reference/android/support/annotation/RestrictTo)\n - [Size](/reference/android/support/annotation/Size)\n - [StringDef](/reference/android/support/annotation/StringDef)\n - [StringRes](/reference/android/support/annotation/StringRes)\n - [StyleableRes](/reference/android/support/annotation/StyleableRes)\n - [StyleRes](/reference/android/support/annotation/StyleRes)\n - [TransitionRes](/reference/android/support/annotation/TransitionRes)\n - [UiThread](/reference/android/support/annotation/UiThread)\n - [VisibleForTesting](/reference/android/support/annotation/VisibleForTesting)\n - [WorkerThread](/reference/android/support/annotation/WorkerThread)\n - [XmlRes](/reference/android/support/annotation/XmlRes)\n-\n\n Enums\n -----\n\n - [RestrictTo.Scope](/reference/android/support/annotation/RestrictTo.Scope)"]]