From the course: Creating a Book Search Engine from Scratch Using Java and GitHub Copilot

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Writing unit tests

Writing unit tests

- [Instructor] We have the entity and we have repository and according to us this should work. But how do we validate that this indeed is working? And this is where the idea of testing shines. Testing is a way to ensure that as a developer, whatever code I'm writing and I'm responsible for, I have an automated way of verifying that the code executes as expected and it returns the results as desired. So far, we have created the entity and the repository and just by saying this should work doesn't matter, because when it is deployed in the production, we must make sure that this is the correct code. So what I will do now is I will write a first test for the repository. We don't need to write the test for the entity because it'll be mostly mocking. So I want to write the real test that connects with the database, and the book repository is the first place we can do that because we have a meaningful business logic for searchBooks that executes a valid SQL query given a search term. So in…

Contents