我有这个测试类
@TransactionConfiguration(defaultRollback = false)
public class CandidateServiceTest extends AbstractServiceTest {
@Test
public void add() {
}
...
}
@ContextConfiguration(locations = { "classpath:/test/BeanConfig.xml" })
public class AbstractServiceTest extends AbstractTransactionalJUnit4SpringContextTests{
...
}
所有方法CandidateServiceTest
都是事务性的。如何更改CandidateServiceTest
所有方法都是NonTransactional?
答案 0 :(得分:1)
不要延长AbstractTransactionalJUnit4SpringContextTests
。只需使用@Transactional
注释,就像使用服务一样:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/test/BeanConfig.xml" })
public class AbstractServiceTest {
}
@TransactionConfiguration(defaultRollback = false)
public class CandidateServiceTest extends AbstractServiceTest {
@Test
public void add() {
// non-transactional test
}
@Test
@Transactional
public void transactionalAdd() {
// transactional test
}
}