Handling transactions in Spring tests
Spring provides a module/utility library for integration tests. The following are the steps to write JUnit tests using the Spring transaction management API and SpringJUnit4ClassRunner
.
We'll reuse the DataAccess
project used in Chapter 1, Getting Familiar with the Spring Framework.
- Create a source folder,
integration
, directly under theDataAccess
project. Spring supports XML-based configuration and wiring beans. Create an XML file,integration.xml
, in theintegration
source package. Modify the XML and define thedataSourceBean
,transactionManagerBean
, andJdbcTemplateBean
Spring beans. The following is the XML body:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
Get Mockito for 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.