Book Image

Mockito for Spring

By : Sujoy Acharya
Book Image

Mockito for Spring

By: Sujoy Acharya

Overview of this book

Table of Contents (12 chapters)
Mockito for Spring
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Unit testing the web layer


We'll build a simple Spring web application with the following functionalities:

  • User registration

  • User login

We'll create the following three layers:

  • A data access layer to store and retrieve data

  • A service layer to perform business logic and data validation

  • Spring controllers to present the UIs and invoke services

In this section, we'll build the controllers and unit test them in isolation from the web server. We have to mock out the service and data access logic.

Perform the following steps to build the web application:

  1. Create a dynamic web project, SpringWeb, and copy the Spring JARs from the Spring MVC project we created in Chapter 1, Getting Familiar with the Spring Framework.

  2. Add the following lines to the web.xml file in order to configure Spring MVC. We have already covered the details in Chapter 1, Getting Familiar with the Spring Framework:

    <web-app xmlns:xsi="...">
      <display-name>SpringWeb</display-name>
      <servlet>
        <servlet-name...