Skip to content

Instantly share code, notes, and snippets.

@jbnunn
Created October 22, 2013 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbnunn/7102350 to your computer and use it in GitHub Desktop.
Save jbnunn/7102350 to your computer and use it in GitHub Desktop.
Using an in-memory database for Play! framework testing
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")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment