<https://dev.to/kerooker/writing-reusable-tests-wi...
# kotest
s
That's great, thank you for the guide! I already know some places where I will use it 😁 By the way, I've already extracted many places like that. However, I think some of them can't be rewritten as factories easily: for example, this one: https://github.com/SerVB/e-shop/blob/cd69df8c33e227c5cea9bf72ebac579a699bdf81/auth/src/test/kotlin/io/github/servb/eShop/auth/testContainerEShopAuth.kt#L25-L31
Copy code
fun BehaviorSpec.givenTestContainerEShopAuth(test: suspend GivenContext.(TestApplicationEngine) -> Unit) {
    given("test container e-shop-auth") {
        withTestApplication(Application::testContainerEShopAuth) {
            this@given.test(this)
        }
    }
}
If I rewrite it like a factory, then I have to call it like
Copy code
include(givenTestContainerEShopAuth { app ->
  // ...
})
I think it's not too clean. Maybe something like
Copy code
include.givenTestContainerEShopAuth { app ->
  // ...
}
is better 😀
l
Nice, @SerVB!
Do you have a suggestion on how we can extract that code of yours to the abstract factories?
s
Yep. The variant, as I've said, can be introducing another way of defining includes:
Copy code
include.givenTestContainerEShopAuth { app ->
  // ...
}
This should give not an object of
*Spec
type but of
*Context
type so it can be used inside a spec. I think the syntax should be discussed, though