【发布时间】:2013-05-18 03:30:51
【问题描述】:
我正在尝试使用 Scalatest 在 Play Framework 2.1 测试套件中设置和拆除数据库
我们实际上已经设置了
running(FakeApplication()){
}
但我想在每次单独测试之前设置数据库,根据我对 Scalatest 的理解,您可以使用
override def beforeEach(){
}
所以我尝试从内部运行几个 Squeryl 查询,并得到一些关于 Session 被关闭的错误。
然后我尝试在 beforeEach 方法中创建一个会话:
override def beforeEach(){
import org.squeryl.SessionFactory
Class.forName("org.postgresql.Driver").newInstance()
// classOf[org.postgresql.Driver]
DriverManager.registerDriver(new org.postgresql.Driver)
val props = new Properties()
props.setProperty("user","db")
props.setProperty("password","db")
SessionFactory.concreteFactory = Some(()=>
Session.create(
java.sql.DriverManager.getConnection("jdbc:postgresql://127.0.0.1/db", props),
new PostgreSqlAdapter))
CloudUsers.truncateUsers()
Servers.truncateServers()
}
这已经清除了会话错误,但我现在得到:
Could not run test Controllers.UserTest: java.lang.ExceptionInInitializerError
Throwable escaped the test run of 'Controllers.UserTest': java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError
....
Caused by: java.lang.RuntimeException: There is no started application
所以简而言之,我可以在 Play 中运行 beforeEach 设置方法,还是只需要在每个测试的顶部使用一些引导程序来调整它?
谢谢
汤姆
【问题讨论】:
标签: scala playframework-2.0 scalatest