How to rollback a database transaction when testing services with Spring in JUnit?

前端 未结 4 428
有刺的猬
有刺的猬 2020-12-01 03:19

I have no problem testing my DAO and services, but when I test INSERTs or UPDATEs I want to rollback the transaction and not effect my database.

4条回答
  •  误落风尘
    2020-12-01 03:58

    check out

    http://static.springsource.org/spring/docs/2.5.x/reference/testing.html

    Section 8.3.4 in particular

    Spring has some classes for testing that will wrap each test in a transaction, so the DB is not changed. You can change that functionality if you want too.

    Edit -- based on your more infos, you might want to look at

    AbstractTransactionalJUnit38SpringContextTests at

    http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/test/context/junit38/AbstractTransactionalJUnit38SpringContextTests.html

提交回复
热议问题