Reputation: 3108
I have a basic spring-boot project written in Kotlin and using Flyway for handling database setup.
I want to write integration tests, all in a seperate source folder in src/integrationTest which I set up in gradle.
Now I want to create a kotest TestListener which recreates the database before each spec using flyway.
I was successful with wiring this manually like this:
@Component
class FlywayCleaningTestListener(
private val flyway: Flyway
) : TestListener {
override suspend fun beforeSpec(spec: Spec) {
flyway.clean()
flyway.migrate()
}
}
@SpringBootTest
class RepositoryIntegrationTest(
private val flywayCleaningTestListener: FlywayCleaningTestListener
) : FunSpec({
extensions(flywayCleaningTestListener)
test("foo") {
// the test
}
})
Now I want to go one step further and have this extension applied automatically to all tests in the integrationTest folder.
How can I do this, when the flyway object needs to be injected into the testlistener as a spring dependency?
An (abstract) base test class would also be fine.
Upvotes: 1
Views: 69