From the course: Complete Guide To Java Testing with JUnit 5 & Mockito

Unlock the full course today

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

Challenge: Test a Spring weather application

Challenge: Test a Spring weather application

(bright music) - [Instructor] Let's practice testing Spring Boot applications. With this challenge, you'll write unit tests and integration tests for a weather application. Let's take a look. The controller has a single endpoint that returns the current temperature for a given city from a weather service. To retrieve the weather data, it uses the weather service. Let's take a look at that. The weather service makes a get request to the open weather map API, using a REST template. We pass in the city name, the API key, and a unit for the measurement to ensure the temperature is returned in Fahrenheit. The API key is configured in our application.properties file. We pull it into our class with the at value annotation. There are also two model classes that represent the weather response and its corresponding attributes. Each of these classes should have a unit test and there should be an integration test for the full application. Be sure to consider everything you've learned so far when…

Contents