...

/

Testing the Repository

Testing the Repository

Learn how to perform integration testing for loading, saving, and updating a product.

Global operations

Now that our parts are in place, we can write an integration test for our repository implementation. First, we need to do some things globally for the test scope.

Press + to interact
private val dbConfig: DatabaseConfig[JdbcProfile] =
DatabaseConfig.forConfig("database", system.settings.config)
private val repo = new Repository(dbConfig)
override protected def beforeEach(): Unit = {
flyway.clean()
val _ = flyway.migrate()
super.beforeEach()
}
override protected def afterEach(): Unit = {
flyway.clean()
super.afterEach()
}
override protected def afterAll(): Unit = {
repo.close()
super.afterAll()
}

Here, we clean our database, run the migration, and after we have executed all the tests, close the repository.

Remember: not cleaning the database between tests might be an even more thorough test. ...

loadProduct

Access this course and 1400+ top-rated courses and projects.