Our first unit test

It is now time to write our first unit test.

We will focus on writing tests at the controller level because we have little to no business code or service. The key to writing tests for Spring MVC is the org.springframework.boot:spring-boot-starter-test dependency in our classpath. It will add a few very useful libraries, such as these:

  • hamcrest: This is JUnit's assertion library
  • mockito: This is a mocking library
  • spring-test: This is the Spring testing library

We will test the redirection to the profile page that is created when the user hasn't created their profile yet.

We already have an autogenerated test called MasterSpringMvc4ApplicationTests. It is the most basic kind of test one can write with the Spring test framework: it ...

Get Spring MVC: Designing Real-World Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.