Creating tests for MVC controllers

In the previous chapters, we made a lot of progress in gradually creating our application, but how do we know that it actually does what we want it to do? More importantly, how do we know for sure that after six months, or even a year from now, it will still continue to do what we expected it to do at the very beginning? This question is best answered by creating a set of tests, preferably automated, that run a suite of assertions against our code. This ensures that we constantly get the same and expected output given the specific input. Tests give us the much-needed peace of mind that our application not only elegantly is coded and looks beautiful, but that it also performs reliably and is as error-free as possible.

In Chapter 4, Writing Custom Spring Boot Starters, we left off with our web application fitted with a custom-written Spring Boot starter. We will now create some basic tests to test our web application and to ensure that all the controllers expose the expected RESTful URLs, which we can rely on as the service API. This type of testing is a bit beyond what is commonly known as unit testing as it tests the entire web application, it requires the application context to be fully initialized, and all the beans should be wired together in order to work. This kind of testing is sometimes referred to as integration or service testing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.171.180