In a kotest test ,when setting up beforeTest hooks, it does not work as expected.
The JdbcOperations can not get the connection in the beforetest, but all tests methods are working well.
Actual Behaviour
I want to do some clean database work in the beforeTest.
@MicronautTest(environments = [Environment.TEST], startApplication = false)
class PostRepositoryTest(private val posts: PostRepository, private val template: JdbcOperations) : StringSpec({
"a test" {//test includes database operations worked well.
}
}){
override fun beforeEach(testCase: TestCase) {
val delCount = this.template.prepareStatement("delete from posts") { it ->
it.executeUpdate()
}
print("deleting items: $delCount")
}
}
There is an exception thrown by this.template.prepareStatement.
Steps To Reproduce
I used docker compose to bootstrap the database for testing and running applications.
Expected Behavior
In a kotest test ,when setting up
beforeTest
hooks, it does not work as expected.The
JdbcOperations
can not get the connection in the beforetest, but all tests methods are working well.Actual Behaviour
I want to do some clean database work in the beforeTest.
There is an exception thrown by
this.template.prepareStatement
.Steps To Reproduce
I used docker compose to bootstrap the database for testing and running applications.
The source codes: https://github.com/hantsy/micronaut-sandbox/blob/criteria-api/jdbc-kotlin/src/test/kotlin/com/example/PostRepositoryTest.kt (the beforeTest is commented out here.)
Environment Information
Example Application
https://github.com/hantsy/micronaut-sandbox/blob/criteria-api/jdbc-kotlin/src/test/kotlin/com/example/PostRepositoryTest.kt
Version
3.2.0