Learning Objectives
- Explain what TDD is.
- Implement Unit Test using JUnit & Mockito.
- Implement a REST API using TDD.
Watch the following video How to be Proactive in Life
Main Topics
- TDD.
- Unit Test.
- Mock.
🗣️ "I hear and I forget I see and I remember I do and I understand." Confucius
In TDD you first implement the test then you write the code to achieve the test expected results.This time you will start by runing existing test and then write the code to pass the test.
- Download and sync the project in the repo.
- Open the class MongoWeatherServiceTest and run the tests.
- Read the results and check the code to find what is wrong.
- Implement the code so your tests pass.
- Run your test again and verify that they all pass.
- Write 1 unit test for each method of the WeatherService to verify the correct implementation on the * MongoWeatherService*.
- Open the HealthControllerTest class and run the tests.
- Check the code and understand how to use the Spring Boot testing annotation.
- Create a new class to test the WeatherReportController called WeatherReportControllerTest.
- Copy the configuration annotations you will need from the HealthControllerTest class.
- Implement 1 unit test for each method inside the WeatherReportController.