Created
October 22, 2013 15:05
-
-
Save jbnunn/7102350 to your computer and use it in GitHub Desktop.
Using an in-memory database for Play! framework testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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