开发者

What class should I inherit to create a database integration test in case of Spring?

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() {
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜