Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java spring junit是否默认回滚?_Java_Spring_Junit_Spring Test - Fatal编程技术网

Java spring junit是否默认回滚?

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

我正在使用Spring和Junit测试我的DAO层。这是我的测试:

@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将回滚更改。。