
Explore what unit tests are in Java and why we use them, then demonstrate simple and advanced techniques, share tips, and highlight bad practices to avoid.
A unit test is code that tests the logic inside one unit, typically a method, in isolation, using checks and assertions to ensure each component behaves as expected.
Discover why unit tests are mandatory for modern Java projects and how developers must write meaningful tests to ensure code works as expected, a must-have skill prized by big companies.
Create a spring boot app with two endpoints for get all cars and add new car, using maven, java 17, spring boot 3, spring web, and constructor-injected in-memory repository.
Learn to write unit tests for the car controller's add new car method using Mockito, mock the external car service, and verify a created response with the added car.
Create unit tests for the getAllCars method in the car controller. Mock the car service, verify the response entity matches a 200 status, headers, and a list of cars.
This course presents a way to start with Unit Tests in Java. The examples that I'm providing are inside a Spring Boot App. I think this adds value for you when it comes to getting a clearer picture of Unit Tests in an actual environment that is used by thousands if not millions of apps.
I think that it's important for you to understand that these are my opinions when it comes to unit testing. I'm sure that there are many advice out there which are better than mine. What I'm trying to present here is how I see the Unit Tests after a couple of years of professional experience with them. I try to discuss about different topics that I learned about in the most basic ways.
This course comes up with answers about what are Unit Tests and why it's good to have them. It also has a practical part, in which I present you some code samples of unit testing. In the end, I mention some tips that helped me along the way, and then I enumerate bad practices that I'm trying to avoid.
I hope from the bottom of my heart that this course will help you!