这是我的scalatest文件,它测试savedat方法。savedat在我的表中输入Employeeentry对象,并返回保存的行数,在我的情况下为1:
class databasetest extends FlatSpec {
"this" should "save a row in table" in new App{
DB.withSession{ implicit session : Session =>
Employee.savedat(EmployeeEntry(1,"james","bhagat","ghgas"))
}
}
}
这是有效的:
class databasetest extends Specification {
"this" should {
// val appWithMemoryDatabase = FakeApplication(additionalConfiguration = inMemoryDatabase("test"))
"test savedat" in new WithApplication {
DB.withSession{
implicit session :Session =>
Employee.savedat(EmployeeEntry(45,"ketan","bhagat","ghgas")) must be equalTo (1)
}
}
错误是Play经常需要一个正在运行的应用程序作为WithApplication对象提供的上下文。