0

I have a test like this:

@ContextConfiguration(locations = { "file:war/WEB-INF/application-context.xml" })
public class ServiceImplTest extends AbstractTestNGSpringContextTests
{
    @Autowired
    private Service service;

    @Rollback(false)
    @Test
    public void testCreate()
    {
           .....
              //save an entity to table_A
      service.save(a);
    }
}

The table_A will be cleaned up; how to stop this cleaning action?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Alex Luya
  • 9,412
  • 15
  • 59
  • 91

1 Answers1

0

Try marking your test class as transactional, which will require you to use springs test classes also.

@RunWith(SpringJUnit4ClassRunner.class),
@ContextConfiguration(locations = { "file:war/WEB-INF/application-context.xml" })
@Transactional
public class ServiceImplTest extends AbstractTestNGSpringContextTests
{
    @Autowired
    private Service service;

    @Test
    @Rollback(false)
    public void testCreate()
    {
           .....
              //save an entity to table_A
      service.save(a);
    }
}

You could also try using @TransactionConfiguration, where txMgr is the name of your transaction manager.:

@RunWith(SpringJUnit4ClassRunner.class),
@ContextConfiguration(locations = { "file:war/WEB-INF/application-context.xml" })
@TransactionConfiguration(transactionManager="txMgr", defaultRollback=false)
public class ServiceImplTest extends AbstractTestNGSpringContextTests
{
  ....
}

The rollback functionality in test is dependent on how you manage your transactions, without that information it is hard to give you a solid answer.

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
  • It seems not roolback but clean first,because after each test,all old data entries in the table disppeared,only the entry that is inserted by test is left. – Alex Luya Nov 02 '12 at 02:08