Java spring junit是否默认回滚?
我正在使用Spring和Junit测试我的DAO层。这是我的测试:Java spring junit是否默认回滚?,java,spring,junit,spring-test,Java,Spring,Junit,Spring Test,我正在使用Spring和Junit测试我的DAO层。这是我的测试: @ContextConfiguration(locations = "classpath:application-context-test.xml") @RunWith(SpringJUnit4ClassRunner.class) public class TestEmployeeDAO { @Autowired private EmployeeDAO employeeDAO; @Test @Transactional pu
@ContextConfiguration(locations = "classpath:application-context-test.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class TestEmployeeDAO {
@Autowired
private EmployeeDAO employeeDAO;
@Test
@Transactional
public void testInsertEmployee(){
Employee employee = new Employee("Abdel Karim");
employeeDAO.insert(employee);
.
.
.
}
}
}
但是当我执行测试并检查数据库时,我发现没有插入任何行,也没有引发任何异常。我不明白为什么,Spring(SpringJUnit4ClassRunner)的默认行为是回滚事务吗
提前感谢。是的,默认情况下回滚为true。要关闭它,请使用:
@Test
@Transactional
@Rollback(false)
public void testInsertEmployee(){
Employee employee = new Employee("Abdel Karim");
employeeDAO.insert(employee);
}
如果要检查是否插入了数据,则需要在测试方法内部执行。。一旦运行该方法,spring将回滚更改。。