Unit testing the data access layer

The data access layer is responsible for managing the database connection, retrieving data from the database, and storing data back to the database. Unit testing the data access layer is very important; if anything goes wrong in this layer, the application will fail. We can unit test the data access logic in isolation from the database and perform integration testing to verify the application and database integrity.

We'll use the Derby database to store real user data. We'll create a utility class to create a database, derbyDB, and create a table with details such as user_data(userId varchar(50), password varchar(50), fname varchar(40), and lname varchar(40)). Skipping the class details for brevity, you can download ...

Get Mockito for Spring now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.