Sto scrivendo un'app Web utilizzando Play 2, Salat (per bongo mongoDB). Vorrei testare alcuni metodi, nel modello di lezione (ad esempio testare il fatto che recupero la lezione giusta da id). Il problema è che non voglio inquinare il mio DB attuale con lezioni fittizie. Come posso utilizzare un DB falso usando Salat e Scala Test? Ecco uno dei miei file di test. Crea due lezioni e la inserisce nel DB, eseguendone alcuni test.Come testare metodi basati su Salat con ScalaTest
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())))
}
}
}
Ho cercato sul Web ma non riesco a trovare un buon collegamento o progetto che utilizzi Salat e ScalaTest.
Grazie per la vostra risposta, ha aiutato molto! Solo una cosa, per cancellare tutti i dati esistenti, è possibile utilizzare questo metodo: db.dropDatabase – TeaBough