O'Reilly logo

Spring MVC Cookbook by Alex Bretet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Injecting Spring Beans into integration tests

This recipe is an example of how to inject Spring managed beans into integration test classes. Even for IT tests, whose first objective is to assess the backend as a blackbox, it is sometimes necessary to reach out technical objects from the intermediate layer.

Getting ready

We will see how to reuse an instance of a Spring managed datasource to be injected in our test class. This datasource will help us to build an instance of jdbcTemplate. From this jdbcTemplate, we will query the database and simulate/validate processes that couldn't be tested otherwise.

How to do it…

  1. We have @Autowired a dataSource SpringBean in our UserControllerIT test. This bean is defined in the test-specific Spring configuration ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required