# VisibleForTesting

Artifact: [androidx.annotation:annotation](https://developer.android.com/jetpack/androidx/releases/annotation) [View Source](https://cs.android.com/search?q=file:androidx/annotation/VisibleForTesting.kt+class:androidx.annotation.VisibleForTesting) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/annotation#1.0.0)

*** ** * ** ***

Common/AllAndroid/JVM
- 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:

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

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

## Summary

| ### Constants |
|---|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting#NONE() = 5` The annotated element should never be called from production code, only from tests. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting#PACKAGE_PRIVATE() = 3` The annotated element would have `package private` visibility. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting#PRIVATE() = 2` The annotated element would have `private` visibility. | Cmn |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting#PROTECTED() = 4` The annotated element would have `protected` visibility. | Cmn |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting#VisibleForTesting(kotlin.Int)(otherwise: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting#otherwise()` The visibility the annotated element would have if it did not need to be made visible for testing. | Cmn |

## Constants

### NONE

Cmn Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/annotation#1.5.0)

```
const val NONE = 5: Int
```

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

This is equivalent to `https://developer.android.com/reference/kotlin/androidx/annotation/RestrictTo.Scope#TESTS`.

### PACKAGE_PRIVATE

Cmn Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/annotation#1.5.0)

```
const val PACKAGE_PRIVATE = 3: Int
```

The annotated element would have `package private` visibility.

### PRIVATE

Cmn Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/annotation#1.5.0)

```
const val PRIVATE = 2: Int
```

The annotated element would have `private` visibility.

### PROTECTED

Cmn Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/annotation#1.5.0)

```
const val PROTECTED = 4: Int
```

The annotated element would have `protected` visibility.

## Public constructors

### VisibleForTesting

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/annotation#1.10.0)

```
VisibleForTesting(otherwise: Int = PRIVATE)
```

## Public properties

### otherwise

Cmn

```
val otherwise: Int
```

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