I want to create a unit test for integration testing. What class should I inherit to be able to commit/rollback transactions? AbstractTran开发者_JAVA技巧sactionalSpringContextTests
is deprecated. It's recommended to use AbstractJUnit38SpringContextTests
instead, but I cannot find how to control transactions there.
Check this and this
In short, you need:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/applicationContext.xml")
public class YourTest {
@Transactional
public void someTest() {
}
}
That would mean you need JUnit 4.x
No need to put the @Transactional
in the method level you can directly place it in class level
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext.xml")
@TransactionConfiguration(defaultRollback=true, transactionManager="transactionManager")
@Transactional
public class YourTest {
@Rollback(true)
public void someTest() {
}
}
精彩评论