7 Test-Driven Development with Spring
WHAT YOU WILL LEARN IN THIS CHAPTER:
- Configuring and caching ApplicationContext
- Injecting dependencies of test fixtures
- Working with transaction management in tests
- Testing web applications
- Using mock objects and other utilities for testing
Applying the Inversion of Control (IoC) pattern alone in an application makes the codebase suitable for unit testing. You can easily create mock dependencies and set them into the object that is being tested. For unit testing, the central unit under focus is the class or the method under test. There should be no environmental dependency—such as a database, a network, or even an IoC container—during unit testing. However, it is not enough to test units separately. Testing units separately is like testing the tires, engine, and doors of a car separately under the assumption that everything will work as expected when you assemble those parts and build the car.
You need to bring some parts of the whole system together to see if they will work. Those parts in a software system usually include objects from several layers, such as existing transactional context and database, network interaction, security context, or IoC container. It would be great if integration testing ...
Get Beginning Spring 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.