While debugging a Parameterized test, I realized the test wouldn't run if the parameters were passed as a List of Lists (List<List<Any>>
), yet worked fine with a List of Arrays (List<Array<Any>>
).
Example classes:
import com.google.common.truth.Truth
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@RunWith(Parameterized::class)
class TestWithList(val input: List<Int>, val output: Int) {
companion object {
@JvmStatic
@Parameterized.Parameters
fun data(): List<List<Any>> =
listOf(
listOf(
listOf(1, 4, 3, 2),
4
)
)
}
@Test
fun `empty test`() {
Truth.assertThat(true).isTrue()
}
}
Throws
IllegalArgumentException: wrong number of arguments
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@RunWith(Parameterized::class)
class TestWithArray(val input: List<Int>, val output: Int) {
companion object {
@JvmStatic
@Parameterized.Parameters
fun data(): List<Array<Any>> =
listOf(
arrayOf(
listOf(1, 4, 3, 2),
4
)
)
}
@Test
fun `empty test`() {
assertThat(true).isTrue()
}
}
Runs perfectly.
Why does passing a List
pass the wrong number of arguments?