0
@ContextConfiguration(classes = { ServiceConfig.class,PersistenceConfiguration.class, MailConfig.class })
@Transactional
public class CreateStatsIT extends AbstractTestNGSpringContextTests {

@Autowired
private UserRepository userRepository;

@Test
@Rollback
@Transactional
public void insertUserIT() {

    User u = new User(1L, "Test");
    u = userRepository.save(s);


    List<User> us = userRepository.findAll();

    System.out.println(us.size());

   }

}

I would expect that the user would not be present in the database after the completion of the test but it is. The Spring Integration Tests documentation describes that the tests rollback automatically and also that @Rollback does not let the transaction be committed.

What am I doing wrong?

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
idipous
  • 2,868
  • 3
  • 30
  • 45
  • Please refer to the answer [here](https://stackoverflow.com/a/34428936). Quoting the solution here for ease of reference. Please replace `AbstractTestNGSpringContextTests` with `AbstractTransactionalTestNGSpringContextTests`. – Krishnan Mahadevan Jun 19 '17 at 04:50
  • Possible duplicate of [Spring + TestNG not transactionally rollback](https://stackoverflow.com/questions/34419775/spring-testng-not-transactionally-rollback) – juherr Jun 23 '17 at 18:59

0 Answers0