Hi. I have this case where I'm writing multiple im...
# kotlintest
a
Hi. I have this case where I'm writing multiple implementations of the same interface, and want to apply the same tests to an instance of each implementation. What's the best way to avoid having to copy/paste all the test cases? I currently have the following (obviously simplified), which I imagine has some room for improvement:
Copy code
fun testSpec(setupFn: () -> Greeter): AbstractFreeSpec.() -> Unit {
    val greeter = setupFn()
    return {
        "Test hello world" {
            greeter.sayHi() shouldBe "Hi"
        }
    }
}

class GreeterServiceTest : StringSpec(testSpec {
    val db = Database.createInMemoryDb()
    val service = GreeterSimulator(db)
    db.seed("classpath:db/seed/greets")
    service
})

class MySimulatorTest : StringSpec(testSpec {
    GreeterSimulator()
})
Is there a more elegant ways of parameterising the SUT of a spec?