使用弹簧使用@Transactional时测试用例失败?

时间:2016-06-17 13:47:22

标签: java spring junit

我正在尝试运行与我的资源类相关的测试用例,我在其中添加了@Transactional注释。

资源类对oracle数据库上的操作有常规的创建,更新,删除方法,但我的测试用例失败了。

代码是: -

资源类: -

@Transactional
public class TestToSAVE {

@ApiOperation(value = "Create new information store definition", notes = "Create a new information store definition and return with its unique id", response = InformationStoreDefinition.class)
    @POST
    @Timed
    public void create() {
       //code for create object and save into database
}

测试用例代码: -

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {TestConfiguration.class})
@Transactional(propagation= Propagation.REQUIRES_NEW,rollbackFor = TransactionException.class)
public class TestToSAVETest  {
//code in test class
}

例外:

org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly

请建议我如何解决此异常。

0 个答案:

没有答案