We have no tests for our Repository class, which handles all the database work. We also don’t have tests for our routes.
We have several options for testing here, but we have to do some refactoring before we can test either of them. For starters, we should move our routes out of our main application into separate classes to test them more easily. But should we refactor code only to gain better testability?
The answer is yes, we should. There are, of course, pros and cons to that, but in general, this approach makes sense. Regardless of pure or impure, we want our code to have a clean structure.
It seems the only parts left to test are the FlywayDatabaseMigrator and our DoobieRepository classes. Testing them will require a running database, so we leave the cozy world of unit tests behind and venture into integration test land. But fear not, we already have some — albeit impure — experience here.
BaseSpec for pure integration tests
As usual, we start by implementing a base class that we can use to provide common settings and functions across our tests.