I try to implement a data driven test for a kotlin function that has several parameters with default values.
In my test definitions I'd like to be able to leave out any combination of arguments that have a default argument in the function declaration. I don't see how that can work (without a separate branch for each combination of default values).
Maybe it is better explained by code:
import kotlin.test.assertEquals
fun foobalize(start: Int = 0, separator: String = "\t", convert: Boolean = false): Int {
return 0 // implementation omitted
}
data class TestSpec(
val start: Int? = null, // null should mean: Don't pass this argument to foobalize(), but use its default value
val separator: String? = null, // dito
val convert: Boolean? = null, // dito
val expectedResult: Int
)
fun testFoobalize(testSpec: TestSpec) {
// How to call foobalize here with values from TestSpec, but leave out parameters that are null,
// so that the defaults from the fopobalize() function declaration are used???
val actualResult = foobalize(start = testSpec.start)
assertEquals(testSpec.expectedResult, actualResult)
}
Is there some completely different way to do this?