我正在尝试学习Play scala中的单元测试,但是我遇到了一些问题。我正在尝试像这样在我的模型层上运行多个测试:
"User Model" should {
"be created and retrieved by username" in {
running(FakeApplication()) {
val newUser = User(username = "weezybizzle",password = "password")
User.save(newUser)
User.findOneByUsername("weezybizzle") must beSome
}
}
"another test" in {
running(FakeApplication()) {
// more tests involving adding and removing users
}
}
}
然而这样做时,我在第二个单元测试中无法连接到数据库,显示连接已关闭。我尝试通过将所有代码封装在在同一个虚拟应用程序上运行的块中来解决此问题,但也没有起作用。
running(FakeApplication()) {
"be created and retrieved by username" in {
val newUser = User(username = "weezybizzle",password = "password")
User.save(newUser)
User.findOneByUsername("weezybizzle") must beSome
}
"another test" in {
// more tests involving adding and removing users
}
}