0

我有这个测试课

@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 ?

4

1 回答 1

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
    }
}
于 2013-10-05T07:31:01.910 回答