<!--
title: Use Kotlin testing idioms
domain: app-frameworks
topic: Testing
language: Kotlin
source: facebook/react-native
updated: 2025-01-27
url: https://awesomereviewers.com/reviewers/react-native-use-kotlin-testing-idioms/
-->

When writing tests in Kotlin, prefer Kotlin-specific testing libraries and language features over their Java equivalents. Use Mockito Kotlin instead of standard Mockito for more idiomatic syntax, and leverage Kotlin language features like `apply` blocks to make test setup code more concise and readable.

For example, instead of:
```kotlin
import org.mockito.Mockito.verify
// ...
val field = OkHttpClientProvider::class.java.getDeclaredField("sClient")
field.isAccessible = true
field.set(null, null)
```

Use:
```kotlin
import org.mockito.kotlin.verify
// ...
val field = OkHttpClientProvider::class.java.getDeclaredField("sClient").apply {
  isAccessible = true
  set(null, null)
}
```

This approach improves test code readability, reduces boilerplate, and takes advantage of Kotlin's expressive syntax to make tests more maintainable.
