https://kotlinlang.org logo
#kotest
Title
# kotest
t

thanksforallthefish

03/25/2021, 1:51 PM
this might be the most stupid question ever, but is data driven tests supposed to work with stringspec?
Copy code
import io.kotest.core.datatest.forAll
import io.kotest.core.spec.style.StringSpec
import io.kotest.data.Row2
import io.kotest.data.row
import io.kotest.matchers.shouldBe

class ParticipantRoleTest : StringSpec({
  "create from string" {
    forAll<Row2<String, *>>(
      "DamageCauser" to row("DamageCauser", ParticipantRole.DamagingParty),
      "Customer" to row("Customer", ParticipantRole.PolicyHolder),
      "Unknown" to row("Unknown", ParticipantRole.Other),
      "Repairer" to row("Repairer", ParticipantRole.Repairer),
    ) { (input, output) ->
      ParticipantRole.fromString(input) shouldBe output
    }
  }
})
this does nothing, tests are not executed but
Copy code
import io.kotest.core.datatest.forAll
import io.kotest.core.spec.style.FunSpec
import io.kotest.data.Row2
import io.kotest.data.row
import io.kotest.matchers.shouldBe

class ParticipantRoleTest : FunSpec({
  context("create from string") {
    forAll<Row2<String, *>>(
      "DamageCauser" to row("DamageCauser", ParticipantRole.DamagingParty),
      "Customer" to row("Customer", ParticipantRole.PolicyHolder),
      "Unknown" to row("Unknown", ParticipantRole.Other),
      "Repairer" to row("Repairer", ParticipantRole.Repairer),
    ) { (input, output) ->
      ParticipantRole.fromString(input) shouldBe output
    }
  }
})
generates 4 tests as expected
mh,
Copy code
import io.kotest.core.datatest.forAll
import io.kotest.core.spec.style.FunSpec
import io.kotest.data.Row2
import io.kotest.data.row
import io.kotest.matchers.shouldBe

class ParticipantRoleTest : FunSpec({
  test("create from string") {
    forAll<Row2<String, *>>(
      "DamageCauser" to row("DamageCauser", ParticipantRole.DamagingParty),
      "Customer" to row("Customer", ParticipantRole.PolicyHolder),
      "Unknown" to row("Unknown", ParticipantRole.Other),
      "Repairer" to row("Repairer", ParticipantRole.Repairer),
    ) { (input, output) ->
      ParticipantRole.fromString(input) shouldBe output
    }
  }
})
also does nothing, maybe I am really missing something in the docs https://kotest.io/docs/framework/data-driven-testing.html
11 Views