一、创建基础类。

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接口的更多相关文章

  1. TestNG参数化测试Spring应用Dubbo接口

    一.配置dubbo的Bean文件: 配置spring-dubbo.xml文件: <dubbo:reference interface="com.datatrees.basisdata. ...

  2. junit参数化测试的使用方法

    JUnit参数化测试的五个步骤:(1)为准备使用参数化测试的测试类指定特殊的运行器 org.junit.runners.Parameterized.(2)为测试类声明几个变量,分别用于存放期望值和测试 ...

  3. junit参数化测试

    在前面的junit4初体验中我就说过,junit参数化测试是一只小怪兽,只逼编码痛点,现在我们这里来整理一下. 看过我前面的那篇初体验的就会发现一个问题,我们的测试代码大量的重复了.在这里先贴出原来的 ...

  4. 计算某天的下一天:黑盒测试之等价类划分+JUnit参数化测试

    题目要求 测试以下程序:该程序有三个输入变量month.day.year(month.day和year均为整数值,并且满足:1≤month≤12.1≤day≤31和1900≤year≤2050),分别 ...

  5. Junit测试Spring应用Dubbo测试框架之-Excel 工具类

    package com.tree.autotest.demo; import com.alibaba.fastjson.JSON;import org.apache.poi.hssf.usermode ...

  6. jmeter测试dubbo接口

    本文讲解jmeter测试dubbo接口的实现方式,文章以一个dubbo的接口为例子进行讲解,该dubbo接口实现的功能为: 一:首先我们看服务端代码 代码架构为: 1:新建一个maven工程,pom文 ...

  7. 同时使用Junit4的@Parameterized参数化测试和Spring容器

    转载:http://www.jianshu.com/p/d191fe54915f 整合Spring容器 @SpringApplicationConfiguration(classes = Applic ...

  8. JAVAEE——spring02:使用注解配置spring、sts插件、junit整合测试和aop演示

    一.使用注解配置spring 1.步骤 1.1 导包4+2+spring-aop 1.2 为主配置文件引入新的命名空间(约束) 1.3 开启使用注解代替配置文件 1.4 在类中使用注解完成配置 2.将 ...

  9. Jmeter分布式测试dubbo接口2

    上次我们将dubbo接口与jmeter集成起来,但是jmeter是由java实现的,本身有很多限制,无法实现高并发,我们需要借助分布式来实现大压力测试. 在上次的例子中,我们只是实现了简单的dubbo ...

随机推荐

  1. 六十三 、异步IO

    在IO编程一节中,我们已经知道,CPU的速度远远快于磁盘.网络等IO.在一个线程中,CPU执行代码的速度极快,然而,一旦遇到IO操作,如读写文件.发送网络数据时,就需要等待IO操作完成,才能继续进行下 ...

  2. Check if a user is in a group

    groups or groups user

  3. 【jzyzoj】【p1320 patrol】 巡逻(网络流最小割例题)

    描述 Description FJ有个农场,其中有n块土地,由m条边连起来.FJ的养牛场在土地1,在土地n有个新开张的雪糕店.Bessie经常偷偷溜到雪糕店,当Bessie去的时候,FJ就要跟上她.但 ...

  4. bzoj 4017: 小Q的无敌异或

    4017: 小Q的无敌异或 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 593  Solved: 197[Submit][Status][Discu ...

  5. 【线段树】hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 I. Minimum

    题意:给你一个序列(长度不超过2^17),支持两种操作:单点修改:询问区间中最小的ai*aj是多少(i可以等于j). 只需要线段树维护区间最小值和最大值,如果最小值大于等于0,那答案就是minv*mi ...

  6. 【线性筛】【质因数分解】【约数个数定理】hdu6069 Counting Divisors

    d(x)表示x的约数个数,让你求(l,r<=10^12,r-l<=10^6,k<=10^7) #include<cstdio> using namespace std; ...

  7. [转]MySQL 数据类型(二)

    MySQL 的数值数据类型可以大致划分为两个类别,一个是整数,另一个是浮点数或小数.许多不同的子类型对这些类别中的每一个都是可用的,每个子类型支持不同大小的数据,并且 MySQL 允许我们指定数值字段 ...

  8. [转]解析UML建模语言中的UML图分类、 UML各种图形及作用

    本文向大家介绍一下UML图分类,作为一种建模语言,UML的定义包括UML语义和UML表示法两个部分. UML图大致可分为五类,共有九种图形. AD: 本文和大家重点讨论一下UML图分类,标准建模语言U ...

  9. 移动应用安全开发指南(Android)--数据存储

    1.数据存储 概述 移动应用经常需要在某些场景下(比如用户登录)处理和用户或业务相关的敏感数据,有时候为满足某些业务需求,需要把这些敏感数据存储在本地,如果不对这些数据进行适当处理,就有可能存在敏感信 ...

  10. 技术分享:杂谈如何绕过WAF(Web应用防火墙)(转)

    0×01开场白 这个议题呢,主要是教大家一个思路,而不是把现成准备好的代码放给大家. 可能在大家眼中WAF(Web应用防火墙)就是"不要脸"的代名词.如果没有他,我们的" ...