网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

junit单元测试事务自动回滚的方法

本篇内容主要讲解“junit单元测试事务自动回滚的方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“junit单元测试事务自动回滚的方法”吧!

我们提供的服务有:成都网站设计、网站制作、微信公众号开发、网站优化、网站认证、松滋ssl等。为上1000家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的松滋网站制作公司

junit 单元测试事务会自动回滚。 通过@Rollback(true)注解来实现,默认是true,事务会回滚,可以不写。false时事务不会回滚,数据会写到数据库中。

package com.xiaolyuh.service;
 
import java.util.Date;
 
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
 
import com.alibaba.fastjson.JSON;
import com.xiaolyuh.entity.RewardCouponDetail;
import com.xiaolyuh.mapper.RewardCouponDetailMapper;
 
@RunWith(SpringRunner.class)
@SpringBootTest
public class RewardCouponDetailServiceTest{
 
	private static final Logger logger = LoggerFactory.getLogger(RewardCouponDetailServiceTest.class);
	
	@Autowired
	private RewardCouponDetailMapper rewardCouponDetailMapper;
    
    
	@Test
	@Transactional
	@Rollback(true)// 事务自动回滚,默认是true。可以不写
	public void TestCustomer(){
		RewardCouponDetail rewardCouponDetail = new RewardCouponDetail();
		rewardCouponDetail.setRewardInfoId(1L);
		rewardCouponDetail.setCouponId("1");
		rewardCouponDetail.setCouponDetailId(1L);
		rewardCouponDetail.setCreateTime(new Date());
		rewardCouponDetailMapper.insert(rewardCouponDetail);
		logger.info(JSON.toJSONString(rewardCouponDetail));
		Assert.assertNotNull(rewardCouponDetail.getId());
	}
	
}

到此,相信大家对“junit单元测试事务自动回滚的方法”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


本文标题:junit单元测试事务自动回滚的方法
网站链接:http://bjjierui.cn/article/josocs.html

其他资讯