Introduction: Driving the Database Layer

Get yourself introduced to what we will learn in this section.

TDD for Wordz database layer

In this section, we will implement a database adapter for one of our ports in the domain model, represented by the WordRepository interface. This will allow our domain model to fetch words to guess from a real database, in this case, using the popular open source database Postgres. We will test-drive both the database setup and the code that accesses the database. To help us do that, we will use a test framework that is designed to simplify writing database integration tests, called DBRider.

By the end of the section, we will have written an integration test against a running database, implemented the fetchesWordByNumber() method from the WordRepository interface, and used the JDBI database access library to help us. We will create a database user with permissions on a table storing words to guess. We will create that table, then write a SQL query that JDBI will use to retrieve the word we are looking for. We will use a named parameter SQL query to avoid some application security issues caused by SQL injections.

Section goals

In this section, We are going to cover the foundations of database integration testing with DBRider. Throughout these lessons, we'll explore the basics, drive production code, and build adapters for WordRepository and GameRepository.

Get hands-on with 1200+ tech skills courses.