Back to all reviewers

Use Kotlin testing idioms

facebook/react-native
Based on 2 comments
Kotlin

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.

Testing Kotlin

Reviewer Prompt

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:

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

Use:

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.

2
Comments Analyzed
Kotlin
Primary Language
Testing
Category

Source Discussions