Topic 19
■■■
Spring Testing
When developing applications for enterprise use, testing is an important way to ensure that the
completed application performs as expected and fulfills all kinds of requirements (architectural,
security, user requirements, and so on).
Every time a change is made, you should ensure that the changes that were introduced don't impact
the existing logic. Maintaining an ongoing build and test environment is critical for ensuring high-
quality applications. Reproducible tests with high coverage for all your code allow you to deploy new
applications and changes to applications with a high level of confidence.
In an enterprise development environment, there are many different kinds of testing that target
each layer within an enterprise application, and each kind of testing has its own characteristics and
requirements.
In this chapter, we will discuss the basic concepts involved in the testing of various application
layers, especially in the testing of Spring-powered applications. We also will cover the ways in which
Spring makes implementing the test cases of various layers easier for developers. Specifically, this
chapter will cover the following topics:
Enterprise testing framework: We will briefly describe an enterprise testing
·
framework. We will discuss various kinds of testing and their purposes. In this
chapter, we will focus on unit testing, targeting various application layers.
Logic unit test: The finest unit test is to test only the logic of the methods within a
·
class, with all other dependencies being "mocked" with the correct behavior. In
this chapter, we will discuss the implementation of logic unit testing for the Spring
MVC controller classes, with the help of a Java mock library to perform the
mocking of a class's dependencies.
Integration unit test: In an enterprise testing framework, integration testing refers
·
to testing the interaction of a group of classes within different application layers
for a specific piece of business logic. Typically, in an integration testing
environment, the service layer should test with the persistence layer, with the
backend database available. However, as application architecture evolves and the
maturity of lightweight in-memory databases evolves, it's now a common practice
to "unit test" the service layer with the persistence layer and backend database as
a whole. For example, in this chapter, we will use JPA 2, with Hibernate and Spring
Data JPA as the persistence provider and with H2 as the database. In this
architecture, it's of less importance to "mock" Hibernate and Spring Data JPA
when testing the service layer. As a result, in this chapter, we will discuss testing of
the service layer together with the persistence layer and the H2 in-memory
database. This kind of testing is generally referred to as integration unit testing,
which sits in the middle of unit testing and full-blown integration testing.
Frontend unit test: Even if we test every layer of the application, after the
·
application is deployed, we still need to ensure that the entire application works as
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home