Is it possible to evaluate test config lazily? Her...
# kotest
b
Is it possible to evaluate test config lazily? Here's my use-case:
Copy code
abstract class SomeParameterBasedTest<T>(abstract val data: List<T>) {
  // Junit example here, but wonder how that would look in kotest
  @Test
  fun execute() {
    data.forEach {
     // Testing code using parseResult<T>()
    }
  }

  abstract fun <T> parseResult(res: String): T
}

class OneKindOfTest: SomeParameterBasedTest<Int>(listOf(1,2,3)) {
  override fun parseResult(res: String): Int = res.toInt()
}
e
b
Kinda, although that still requires the extending (as opposed to abstract) class to include it
e
not sure I see the difference.. I think this is what it would look like.
Copy code
class OneKindOfTest : FunSpec({
   include(
      someParameterBasedTest(
         listOf(1, 2, 3),
         { res -> res.toInt() }
      )
   )
})

fun <T> someParameterBasedTest(
   val data: List<T>,
   val parseResult: (res: String) -> T
) = funSpec {
   test("execute") {
      // Testing code using parseResult
   }
}
b
The difference is that this way doesn't force the implementing class to override that function
Also doesn't add the tests automatically
e
you must pass the function
If. you want to rely on the type system to find implementations of
somePArameterBasedTest
I guess that makes a difference