Book Image

Mockito for Spring

By : Sujoy Acharya
Book Image

Mockito for Spring

By: Sujoy Acharya

Overview of this book

Table of Contents (12 chapters)
Mockito for Spring
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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.

  1. Create a source folder, integration, directly under the DataAccess project. Spring supports XML-based configuration and wiring beans. Create an XML file, integration.xml, in the integration source package. Modify the XML and define the dataSourceBean, transactionManagerBean, and JdbcTemplateBean 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"
      xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
     
      <bean id="dataSourceBean"
        class="org.springframework.jdbc.datasource.
        ...