Trying to write unit test for private functions using WhiteBox (I know I shouldn't, but it's not my decision) Class sample:
class Repository {
private fun foo1(items: List<String>) {
println(items)
}
private suspend fun foo2 (items: List<String>) {
println(items)
}
}
And my tests:
val repository = = spyk(Repository(), recordPrivateCalls = true)
@Test
fun test1() = runBlocking {
Whitebox.invokeMethod<Unit>(
repository,
"foo1",
listOf("")
)
}
@Test
fun test2() = runBlocking {
Whitebox.invokeMethod<Unit>(
repository,
"foo2",
listOf("")
)
}
test1() works, but test2 returns an error:
No method found with name 'foo2' with parameter types: [ java.util.Collections$SingletonList ]
How can I solve it?
Using Kotlin 1.3