저는 Play 2, Salat (mongoDB bindin의 경우)를 사용하여 웹 응용 프로그램을 작성하고 있습니다. Lesson Model에서 몇 가지 메서드를 테스트하고 싶습니다. (예를 들어 id로 올바른 레슨을 검색한다는 사실을 테스트 할 수 있습니다.) 문제는 현재의 DB를 더미 레슨으로 오염시키고 싶지 않다는 것입니다. Salat와 Scala Test를 사용하여 어떻게 가짜 DB를 사용할 수 있습니까? 여기에 내 테스트 파일 중 하나가 있습니다. 그것은 두 개의 수업을 만들고 그것을 DB에 삽입하고 그것에 대해 몇 가지 시험을합니다.ScalaTest로 Salat을 기반으로 메서드를 테스트하는 방법
LessonSpec extends FlatSpec with ShouldMatchers {
object FakeApp extends FakeApplication()
val newLesson1 = Lesson(
title = "lesson1",
level = 5,
explanations = "expl1",
questions = Seq.empty)
LessonDAO.insert(newLesson1)
val newLesson2 = Lesson(
title = "lesson2",
level = 5,
explanations = "expl2",
questions = Seq.empty)
LessonDAO.insert(newLesson2)
"Lesson Model" should "be retrieved by level" in {
running(FakeApp) {
assert(Lesson.findByLevel(5).size === 2)
}
}
it should "be of size 0 if no lesson of the level is found" in {
running(FakeApp) {
Lesson.findByLevel(4) should be(Nil)
}
}
it should "be retrieved by title" in {
running(FakeApp) {
Lesson.findOneByTitle("lesson1") should be(Some(Lesson("lesson1", 5, "expl1", List())))
}
}
}
웹에서 검색했지만 Salat 및 ScalaTest를 사용하는 좋은 링크 또는 프로젝트를 찾을 수 없습니다.
답변 해 주셔서 감사합니다. 많은 도움이되었습니다. 한 가지 기존 데이터를 지우려면 다음 방법을 사용하면됩니다. db.dropDatabase – TeaBough