public
Created

Using an in-memory database for Play! framework testing

  • Download Gist
gistfile1.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
class TestCountriesSpec extends Specification {
val appWithMemoryDatabase = FakeApplication(additionalConfiguration = inMemoryDatabase())
 
abstract class WithDbData extends WithApplication(appWithMemoryDatabase) {
override def around[T: AsResult](t: => T): Result = super.around {
setupData()
t
}
 
def setupData() {
AppDB.database.withSession { implicit session: Session =>
AppDB.dal.create
AppDB.dal.seedForTests
}
}
}
 
"Countries" should {
 
// Model tests
"be found by country id" in new WithDbData {
val country = AppDB.dal.Countries.findOne(1)
org.name aka "must have a name of Brazil" must equalTo("Brazil")
}
 
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.