0

Following my general question I have a specific issue using spring jdbcTemplate , I want to rollback specific test method after every execution of DAO method below.

Adding @Transactional and @Rollback(true) failed to rollback insert

Also getting connection before/after and rollback it doesn't effect

@Test
@Transactional
@Rollback(true)
public void testInsertUser() {
    Assert.assertEquals(userDAO.insertUser(new User(55616103, true, true, false)), true);
}

How should I rollback unit test using TestNG framework? most answers use Junit's @RunWith(SpringJUnit4ClassRunner.class)

I failed auto wiring the jdbcTemplate using TestNG:

@Autowired
private JdbcTemplate jdbcTemplate;

But succeeded using SpringJUnit4ClassRunner with including Configuration class includes jdbcTemplate/DataStource

Do TestNG have option to execute using Spring context?

user7294900
  • 47,183
  • 17
  • 74
  • 157

1 Answers1

1

The solution is to replace the AbstractTestNGSpringContextTests with AbstractTransactionalTestNGSpringContextTests.

reference: Spring + TestNG not transactionally rollback