Why are transactions not rolling back when using SpringJUnit4ClassRunner/MySQL/Spring/Hibernate

前端 未结 5 1241
谎友^
谎友^ 2021-02-06 16:04

I am doing unit testing and I expect that all data committed to the MySQL database will be rolled back... but this isn\'t the case. The data is being committed, even though my

5条回答
  •  遥遥无期
    2021-02-06 16:51

    This must be used

    @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
    @TestExecutionListeners({ TransactionalTestExecutionListener.class })
    @Transactional
    

    TransactionalTestExecutionListener contains isRollback() which rollbacks the transaction after the test method.

提交回复
热议问题