Integration Tests

Learn how to test the FlywayDatabaseMigrator and the repository.

Testing the FlywayDatabaseMigrator

To verify the basic behavior of our FlywayDatabaseMigrator, we write a simple test.

Press + to interact
"thedatabaseisnotavailable"must{
"throw an exception" in {
val cfg = DatabaseConfig(
driver = "This is no driver name!",
url = "jdbc://some.host/whatever",
user = "no-user",
pass = "no-password"
)
val migrator: DatabaseMigrator[IO] = new FlywayDatabaseMigrator
val program = migrator.migrate(cfg.url, cfg.user, cfg.pass)
an[FlywayException] must be thrownBy program.unsafeRunSync
}
}

We construct an invalid database configuration within this test and expect that the call to migrate throws an exception. Review lines 3–8. If you remember, we had this issue already and chose not to handle any exceptions but let the calling site do this, for example, via a MonadError instance. ...

Get hands-on with 1400+ tech skills courses.