Are you looking for an advent calendar? You found it!

Spring MVC Test Tutorial

Superhero Blasting OffDo you want to learn an easy way to write tests for Spring MVC applications?

If you are working with Spring MVC, I can guarantee that the answer to this question is yes. Automated tests saves you time, money and a lot of headache. And yet, writing comprehensive tests for Spring MVC controllers has been a complex task. The problem is that if a task is complex, time consuming and it is not absolutely necessary, you are less likely to finish it. That is how we humans work.

I have spend countless hours of writing tests to Spring MVC applications and the results were still mediocre at best. I knew that important areas of my applications were left untested but that was a compromise I had to make. If you have tried writing tests to Spring MVC applications, I am sure that you know what I am talking about here.

The Spring MVC Test framework solves these problems. My Spring MVC Test tutorial teaches you everything you need to know about the Spring Test MVC framework (aka spring-test-mvc).

Let’s move on and find out how you can write both unit and integration tests for Spring MVC applications.

Introducing: Unit Testing of Spring MVC Controllers

This three-part tutorial describes how you can write unit tests for Spring MVC controllers. This tutorial consists of the following blog posts:

If you prefer watching videos over reading blog posts, you can watch the video version of this tutorial.

Introducing: Integration Testing of Spring MVC Applications

This eight-part tutorial describes how you can write integration tests for Spring MVC applications. The parts of this tutorial are described in the following:

What Happens Next?

Congratulations. You have now taken the first and very important step of a long journey. Your next step is to put the lessons learned into action. Don’t just think about doing it when you have time to do it. Do it right now.

Additional Reading:

Other Resources

This section showcases useful material created by other developers. If you have written a blog post or recorded a video about Spring MVC Test (or testing in general), and you want to include it to this section, ping me on Twitter and I will check it out. If I think that it is useful, I will add it to this section.

Spring Test Framework

Reference Manuals and Official Guides

Blog Posts

Videos

Other Testing Tools

  • AssertJ provides a rich set of fluent assertions for both unit and integration tests.
  • JUnit is the most popular testing framework for Java programming language.
  • catch-exception is a library which catches exceptions and makes them available for further analysis.
  • DbUnit is a JUnit extension which is used to initialize the database into a known state before integration tests are run. It is also to used to write assertions for the data which is stored to a relational database.
  • Hamcrest is a library which provides matchers for both unit and integration tests.
  • HtmlUnit is a headless browser for Java. It is often used for testing purposes but you can also use it for retrieving information from web pages.
  • JMeter is a popular performance testing tool.
  • Mockito is a very popular mocking framework.
  • NoSQLUnit is a JUnit extension which is used to initialize a NoSQL database into a known state before our tests are run. It is also to used to write assertions for the data which is stored to a NoSQL database.
  • Spring Test DbUnit integrates the Spring Test framework with DbUnit.
  • Spring Test MVC HtmlUnit integrates the Spring Test MVC framework with HtmlUnit.
  • REST-Assured is a testing framework for REST APIs.

Reference Manuals and Official Guides

Blog Posts

Videos