Junit参数化测试Spring应用Dubbo接口
一、创建基础类。
package com.tree.autotest; import org.junit.Before;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestContextManager;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; /**
* 规则包:
* 规则编码:
* 规则名称:
* 规则条件:
* <p>
* Created by zhf2015 on 16/8/1.
*/
//@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/spring-context.xml"})
@Configuration
public class BaseJunit4Test extends AbstractJUnit4SpringContextTests { protected TestContextManager testContextManager;
@Before
public void setUpContext() throws Exception {
this.testContextManager = new TestContextManager(getClass());
this.testContextManager.prepareTestInstance(this);
} } 二、创建测试类,继承基础类。
package com.tree.autotest.testcase.BillDetailTypeService; import com.datatrees.basisdata.bankbill.model.Bill;
import com.datatrees.basisdata.bankbill.service.BillService;
import com.tree.autotest.BaseJunit4Test;
import com.tree.autotest.commons.CommonUtil_2;
import com.tree.autotest.commons.TestCase;
import com.tree.autotest.jdbc.DBIdConstant;
import com.tree.autotest.jdbc.ManagedSqlUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map; /**
* Created by lyh on 17/2/13.
*/
@RunWith(value=Parameterized.class)
public class TestSelectListByUserId2 extends BaseJunit4Test{
// ApplicationContext factory=new ClassPathXmlApplicationContext("classpath:/spring-context.xml");
@Autowired
private BillService billService;
// private BillService billService = (BillService)factory.getBean("billService");
private static final Logger logger = LoggerFactory.getLogger(TestSelectListByUserId2.class); private boolean handleOk;
private String insertSql1;
private static String excel;
private static Map allCases;
private Integer testUser; @Parameterized.Parameters
public static Collection<Integer[]> getTestParameters(){ List<Integer[]> list = new ArrayList<Integer[]>();
list.add(new Integer[]{2000998248}); //expected,valueOne,valueTwo
list.add(new Integer[]{2000020021});
list.add(new Integer[]{2001999335});
String st=list.toString();
System.out.println("list值:" + st); return list; }
public TestSelectListByUserId2(Integer userid){
this.testUser = userid;
} @Before
public void setUp() throws SQLException {
//获取excel用例列表
excel = "src/main/resources/case/BillService/TestSelectListByUserId.xlsx";
allCases = CommonUtil_2.getAllCases(excel);
System.out.println("setUp 执行");
// //获取用户ID
TestCase testcase = CommonUtil_2.getTestCaseBean(allCases, "case1", "case1-1");
testUser =Integer.valueOf(testcase.param1);
//获取SQL
insertSql1 = testcase.stepSql;
//删除,添加数据
handleOk &= deleteData(testUser);
handleOk &= ManagedSqlUtil.insertBySql(insertSql1, DBIdConstant.MySql_Basisdata_ID); } @Test
public void test_case_1() throws Exception {
//++++++++++++++实际值+++++++++++++
List<Bill> actual_list =
billService.selectListByUserId(testUser);
System.out.println("testUser值:"+testUser);
//++++++++++++++验证+++++++++++++
Assert.assertNotNull("测试失败",actual_list);
for(int i=0;i<actual_list.size();i++) {
Assert.assertEquals("测试失败",actual_list.get(i).getUserId(),testUser);
}
System.out.println("actual_list的size:"+actual_list.size());
} @After
public void tearDown() { deleteData(testUser);
System.out.println("tearDown 执行");
} //定义数据清理
public boolean deleteData(Integer userId) {
String deleteSql1 = "delete from t_bill where UserId="+userId+";";
handleOk &= ManagedSqlUtil.deleteBySql(deleteSql1, DBIdConstant.MySql_Basisdata_ID);
return handleOk;
}
} 三、配置文件和数据文件和上一篇文章一致。
Junit参数化测试Spring应用Dubbo接口的更多相关文章
- TestNG参数化测试Spring应用Dubbo接口
一.配置dubbo的Bean文件: 配置spring-dubbo.xml文件: <dubbo:reference interface="com.datatrees.basisdata. ...
- junit参数化测试的使用方法
JUnit参数化测试的五个步骤:(1)为准备使用参数化测试的测试类指定特殊的运行器 org.junit.runners.Parameterized.(2)为测试类声明几个变量,分别用于存放期望值和测试 ...
- junit参数化测试
在前面的junit4初体验中我就说过,junit参数化测试是一只小怪兽,只逼编码痛点,现在我们这里来整理一下. 看过我前面的那篇初体验的就会发现一个问题,我们的测试代码大量的重复了.在这里先贴出原来的 ...
- 计算某天的下一天:黑盒测试之等价类划分+JUnit参数化测试
题目要求 测试以下程序:该程序有三个输入变量month.day.year(month.day和year均为整数值,并且满足:1≤month≤12.1≤day≤31和1900≤year≤2050),分别 ...
- Junit测试Spring应用Dubbo测试框架之-Excel 工具类
package com.tree.autotest.demo; import com.alibaba.fastjson.JSON;import org.apache.poi.hssf.usermode ...
- jmeter测试dubbo接口
本文讲解jmeter测试dubbo接口的实现方式,文章以一个dubbo的接口为例子进行讲解,该dubbo接口实现的功能为: 一:首先我们看服务端代码 代码架构为: 1:新建一个maven工程,pom文 ...
- 同时使用Junit4的@Parameterized参数化测试和Spring容器
转载:http://www.jianshu.com/p/d191fe54915f 整合Spring容器 @SpringApplicationConfiguration(classes = Applic ...
- JAVAEE——spring02:使用注解配置spring、sts插件、junit整合测试和aop演示
一.使用注解配置spring 1.步骤 1.1 导包4+2+spring-aop 1.2 为主配置文件引入新的命名空间(约束) 1.3 开启使用注解代替配置文件 1.4 在类中使用注解完成配置 2.将 ...
- Jmeter分布式测试dubbo接口2
上次我们将dubbo接口与jmeter集成起来,但是jmeter是由java实现的,本身有很多限制,无法实现高并发,我们需要借助分布式来实现大压力测试. 在上次的例子中,我们只是实现了简单的dubbo ...
随机推荐
- 前端读者 | Javascript设计模式理论与实战:状态模式
本文来自 @狼狼的蓝胖子:链接:http://luopq.com/2015/11/25/design-pattern-state/ 在软件开发中,很大部分时候就是操作数据,而不同数据下展示的结果我们将 ...
- 【转载】FloatingActionButton源码解析
原文地址:https://github.com/Rowandjj/my_awesome_blog/blob/master/fab_anlysis/README.md loatingActionButt ...
- HDU 4891 The Great Pan
模拟题. #include<map> #include<set> #include<ctime> #include<cmath> #include< ...
- ZOJ 3498 Javabeans
脑筋急转弯. 如果是偶数个,那么第一步可以是$n/2+1$位置开始到$n$都减去$n/2$,后半段就和前半段一样了. 如果是奇数个,那么第一步可以是$(n+1)/2$位置开始到$n$都减去$(n+1) ...
- SpringBoot+Mybatis整合实例
前言 大家都知道springboot有几大特点:能创建独立的Spring应用程序:能嵌入Tomcat,无需部署WAR文件:简化Maven配置:自动配置Spring等等.这里整合mybatis,创建一个 ...
- B/S架构和C/S架构
一.B/S架构 B/S结构(Browser/Server,浏览器/服务器模式),是WEB兴起后的一种网络结构模式,WEB浏览器是客户端最主要的应用软件.这种模式统一了客户端,将系统功能实现的核心部分集 ...
- BestCoder Round #65 (ZYB's Game)
ZYB's Game Accepts: 672 Submissions: 1207 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- 洛谷P1113 杂务
题目描述 John的农场在给奶牛挤奶前有很多杂务要完成,每一项杂务都需要一定的时间来完成它.比如:他们要将奶牛集合起来,将他们赶进牛棚,为奶牛清洗乳房以及一些其它工作.尽早将所有杂务完成是必要的,因为 ...
- 【CCpp程序设计2017】简单进销存
题目:简单进销存 功能要求: 实现如下的菜单(按数字选择菜单功能): 1. 显示存货列表 2. 入库 3. 出库 4. 退出程序 实现菜单对应功能(需记录货物的型号.数量等信息): 程序启动时从文件中 ...
- 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分
E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...