Production Code for Database Integration Test
Explore how to test-drive the database layer in Java by creating an adapter that implements WordRepository. Learn to write integration tests using DBRider and Jdbi to fetch data from PostgreSQL, including setting up test data and aligning schema with test methods for effective TDD.
We'll cover the following...
The next step is to add the missing Arrange, Act, and Assert code to the fetchesWord() test.
Driving out the production code
Our goal is to test-drive code to fetch a word from the database. We want that code to be in a class that implements the WordRepository interface, which we defined in the domain model. We’ll want to design enough of our database schema to support this. By starting to add code to the Assert step, we can drive out an implementation quickly. This is a useful technique— writing the test by starting with the Assert step so that we start with the desired outcome. We can then work backward to include everything necessary for delivering it: