【发布时间】:2016-02-23 02:43:20
【问题描述】:
我正在尝试编写一个测试来检查是否设置了正确的数据库,但断言永远不会触发,并且一切都成功结束(即使它应该失败):
import anorm._
import org.scalatestplus.play._
import play.api.db.DB
class Housekeeping extends PlaySpec with OneServerPerSuite {
// Make sure the test database is loaded
"test connection to test database" in {
DB.withConnection { implicit connection =>
SQL("SELECT * FROM accounts WHERE ID = 1").withResult(res => {
val row = res.head.row
val name = row.asMap("accounts.name")
println(name) // Prints to console
name mustEqual "this should fail"
println("HERE") // Never prints to console
})
}
}
}
控制台:
[info] Housekeeping:
[info] - application - Creating Pool for datasource 'default'
tyler
[info] - test connection to test database
[info] - application - Shutting down connection pool.
我不确定为什么什么也没发生,因为我从数据库中得到了正确的名称。我找不到任何有关执行异步测试的文档,我认为这可能是问题的一部分。
【问题讨论】:
标签: scala unit-testing playframework anorm