This workshop will be retired on January 8, 2022.
Controller Testing9:39 with Chris Ramacciotti
In this video we begin our work in testing the weather app, starting with our controllers. The Spring test framework provides some nice features for testing requests to specific URIs without firing up an entire Spring application.
Mock MVC Result Matchers
What you "expect" after performing a request on a
MockMvc object is called a
ResultMatcher. Typically your options will come from the
MockMvcResultMatchers class. Some things you can examine are the following:
content(): check the response body for actual content in the HTTP response
flash(): check for certain flash attributes
model(): check for model attributes
jsonPath(...): check for content in an HTTP response body that is in the JSON format (e.g. for a REST API)
For a full list of matchers, see the Spring docs for org.springframework.test.web.servlet.result.MockMvcResultMatchers.
Sync Your Code to the Start of this Video
git checkout -f v3
Using Git with this Workshop
See the README on Github for information on how to use Git with this repo to follow along with this workshop.
You need to sign up for Treehouse in order to download course files.Sign up