【发布时间】:2021-11-25 08:50:10
【问题描述】:
我在一个 Micronaut 项目中创建了 Kotest StringSpec 测试,并尝试清除数据库中的数据。
@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")
}
}
this.template.prepareStatement 语句由于无法获取数据库连接的异常而失败。
【问题讨论】: