Spring boot test @Transactional not saving

后端 未结 5 1382
别那么骄傲
别那么骄傲 2020-12-17 21:24

I\'am trying to do a simple Integration test using Spring Boot Test in order to test the e2e use case. My test does not work because I\'am not able to make the repository sa

5条回答
  •  既然无缘
    2020-12-17 22:17

    @RunWith(SpringJUnit4ClassRunner.class)
    @SpringApplicationConfiguration(classes = Application.class)
    public class SmokeTest {
    
        @Autowired
        UserController userController;
    
        @Autowired
        UserDao userDAO;
    
        @Rollback(false) // This is key to avoid rollback.
        @Test   
        public void contextLoads() throws Exception {
            System.out.println("Hiren");
    
            System.out.println("started");
            userDAO.save(new User("tyx", "x@x.com"));
        }
    }
    

    Refer @Rollback(false) is key to avoid rollback.

提交回复
热议问题