这是我的代码:
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@RunWith(SpringRunner.class)
public class UserServiceTest {
@Resource
private UserDao userDao;
@Test
public void save1() {
User user1 = new User("tom", "tom-pass");
User user2 = new User("jerry ", "jerry-pass");
userDao.save(user1);
userDao.save(user2);
}
@Test
public void save2() {
User user1 = new User("tom", "tom-pass");
User user2 = new User("jerry ", "jerry-pass");
userDao.save(user1);
userDao.save(user2);
List<User> all = userDao.findAll();
Assert.assertTrue(all.size() >= 2);
}
}
经过测试,我发现第一种方法可以自动回滚,但第二种方法不起作用,为什么?