Book Image

Mastering Spring MVC 4

By : Geoffroy Warin
Book Image

Mastering Spring MVC 4

By: Geoffroy Warin

Overview of this book

<p>Spring MVC is the ideal tool to build modern web applications on the server side. With the arrival of Spring Boot, developers can really focus on the code and deliver great value, leveraging the rich Spring ecosystem with minimal configuration.</p> <p>Spring makes it simple to create RESTful applications, interact with social services, communicate with modern databases, secure your system, and make your code modular and easy to test. It is also easy to deploy the result on different cloud providers.</p> <p>Mastering Spring MVC will take you on a journey from developing your own web application to uploading it on the cloud.</p> <p>You begin by generating your own Spring project using Spring Tool suite and Spring Boot.</p> <p>As you develop an advanced-level interactive application that can handle file uploads as well as complex URLs, you will dive into the inner workings of Spring MVC and the principles of modern web architectures.</p> <p>You will then test, secure, and optimize your Spring web application and design RESTful services that will be consumed on the frontend.</p> <p>Finally, when everything is ready, you will release your application on a cloud provider and invite everyone to see.</p>
Table of Contents (17 chapters)
Mastering Spring MVC 4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The unit tests


The lower level tests we can write are called unit tests. They should test a small portion of code, hence the notion of unit. How you define a unit is up to you; it can be a class or a bunch of closely related classes. Defining this notion will determine what will be mocked (replaced with a dummy object). Are you going to replace the database with a lightweight alternative? Are you going to replace interactions with external services? Are you going to mock-up closely related objects whose behavior is not relevant to the context of what's being tested?

My advice here is to keep a balanced approach. Keep your tests clean and fast, and everything else will follow.

I rarely completely mock the data layer. I tend to use embedded databases for testing. They provide an easy way to load data while testing.

As a rule, I always mock collaboration with external services for two reasons, as follows:

  • The speed of the tests and the possibility to run the tests without connecting to the network...