我有这样的测试:
@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);
}
}
table_A将被清理;如何停止这种清洁行动?
答案 0 :(得分:0)
尝试将您的测试类标记为事务性,这也需要您使用spring测试类。
@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);
}
}
您也可以尝试使用@TransactionConfiguration
,其中txMgr是您的交易管理器的名称。
@RunWith(SpringJUnit4ClassRunner.class),
@ContextConfiguration(locations = { "file:war/WEB-INF/application-context.xml" })
@TransactionConfiguration(transactionManager="txMgr", defaultRollback=false)
public class ServiceImplTest extends AbstractTestNGSpringContextTests
{
....
}
测试中的回滚功能取决于您如何管理您的交易,如果没有这些信息,很难给您一个可靠的答案。