一、配置dubbo的Bean文件:

配置spring-dubbo.xml文件:

 <dubbo:reference interface="com.datatrees.basisdata.bankbill.service.BillService" id="billService" url="dubbo://121.43.177.8:20100" timeout="10000"/>

将dubbo配置文件引入上下文spring-context.xml:

<import resource="spring-dubbo.xml" />


二、定义基础类:

@ContextConfiguration(locations = {"classpath:/spring-context.xml"})
@Configuration
public class BaseTestNGTest extends AbstractTestNGSpringContextTests {
// protected TestContextManager testContextManager;
// @BeforeTest
// public void setUpContext() throws Exception {
// this.testContextManager = new TestContextManager(getClass());
// this.testContextManager.prepareTestInstance(this);
// }
} 二、创建测试类,集成基础类:
1.excel参数化管理测试数据
2.excel管理sql数据
package com.tree.autotest.testcase.BillService;

import com.datatrees.basisdata.bankbill.service.BillService;
import com.tree.autotest.BaseTestNGTest;
import com.tree.autotest.commons.CommonUtil_2;
import com.tree.autotest.commons.TestCase;
import com.tree.autotest.demo.ExcelHandle;
import com.tree.autotest.jdbc.DBIdConstant;
import com.tree.autotest.jdbc.ManagedSqlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.*; import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; /**
* Created by lyh on 17/2/14.
*/
public class TestGetUserEmailNameCount2 extends BaseTestNGTest {
@Autowired
private BillService billService; private boolean handleOk;
private String insertSql1,insertSql2;
private static String excel;
private static Map allCases;
private Integer operatorUserId;
private Integer exceptedvalue;
private TestCase testcase; @BeforeClass
public void init() throws SQLException,IOException {
//获取excel用例列表
excel = "src/main/resources/case/BillService/TestGetUserEmailNameCount.xlsx";
allCases = CommonUtil_2.getAllCases(excel);
//获取用户ID
testcase = CommonUtil_2.getTestCaseBean(allCases, "case1", "case1-1");
operatorUserId = Integer.valueOf(testcase.param1);
//获取SQL
insertSql1 = testcase.stepSql;
insertSql2 = CommonUtil_2.getTestCaseBean(allCases, "case1", "case1-2").stepSql;
//删除,添加数据
handleOk &= deleteData(operatorUserId);
handleOk &= ManagedSqlUtil.insertBySql(insertSql1, DBIdConstant.MySql_Basisdata_ID);
handleOk &= ManagedSqlUtil.insertBySql(insertSql2, DBIdConstant.MySql_Basisdata_ID);
System.out.println("setUp方法执行"); } @DataProvider(name = "testdata")
public Object[][] dataprovide()throws IOException{
System.out.println("dataprovide方法执行");
// return new Object[][]{{2000020013,2},{2001000138,0},{2001000139,2}};
Object[][] testData =ExcelHandle.readXlsx(excel, "工作表2");
return testData;
} @Test(dataProvider="testdata")
public void test_case_1(HashMap<String, String> map) throws Exception { operatorUserId=Integer.valueOf(map.get("userId"));
exceptedvalue =Integer.valueOf(map.get("excepted")); //++++++++++++++实际值+++++++++++++
Integer actual_value =
billService.getUserEmailNameCount(operatorUserId); //预期值
// Integer excepted_value =get_excepted_value(operatorUserId);
//++++++++++++++验证+++++++++++++
Assert.assertEquals(actual_value,exceptedvalue); } @AfterClass
public void tearDown() { operatorUserId = Integer.valueOf(testcase.param1);
deleteData(operatorUserId);
System.out.println("tearDown方法执行");
} //定义数据清理
public boolean deleteData(Integer userId) {
String deleteSql1 = "delete from t_bill where UserId="+userId+";";
String deleteSql2 ="delete from t_user_email where userid="+userId+";";
handleOk &= ManagedSqlUtil.deleteBySql(deleteSql1, DBIdConstant.MySql_Basisdata_ID);
handleOk &= ManagedSqlUtil.deleteBySql(deleteSql2, DBIdConstant.MySql_Basisdata_ID); return handleOk;
}
public Integer get_excepted_value(Integer userId) throws SQLException{
String searchSql="select count(distinct(NameOnCard)) from t_bill where EmailId in (select distinct(EmailId) from t_user_email where UserId="+userId+")" +
" and NameOnCard != '';";
ResultSet rs =ManagedSqlUtil.selectBySql(searchSql,DBIdConstant.MySql_Basisdata_ID);
List<Integer> list = new ArrayList<Integer>();
while (rs.next()){
list.add(rs.getInt(1));
}
return list.get(0);
}
} 四、测试数据文件:
1.准备数据表格

2.测试执行参数表格:

表格:工作表2 中保存测试执行参数数据

五:运行结果:

出现:

												

TestNG参数化测试Spring应用Dubbo接口的更多相关文章

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

    一.创建基础类. package com.tree.autotest; import org.junit.Before;import org.springframework.context.annot ...

  2. testng入门教程10 TestNG参数化测试

    在TestNG的另一个有趣的功能是参数测试.在大多数情况下,你会遇到这样一个场景,业务逻辑需要一个巨大的不同数量的测试.参数测试,允许开发人员运行同样的测试,一遍又一遍使用不同的值. TestNG让你 ...

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

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

  4. TestNG参数化测试

    参数化有两种方法: 第一种:在xml文件中声明 第二种:用@DataProvider注解 先介绍第一种方法: ParameterTest类:用@Parameters({"name" ...

  5. TestNG参数化测试【转】

    原文:http://www.yiibai.com/testng/20130916303.html 在TestNG的另一个有趣的功能是参数测试.在大多数情况下,你会遇到这样一个场景,业务逻辑需要一个巨大 ...

  6. TestNG参数化测试-数据提供程序 @DataProvider方式

    在 testng.xml 中指定参数可能会有如下的不足: 1.如果你压根不用 testng.xml. 2.你需要传递复杂的参数,或者从Java中创建参数(复杂对象,对象从属性文件或者数据库中读取的et ...

  7. TestNG+Jenkins+Maven参数化测试dubbo接口

    1.TestNG参数化测试用例: package com.tree.autotest.testcase.IUserBankSummaryService; import com.datatrees.fi ...

  8. jmeter测试dubbo接口

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

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

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

随机推荐

  1. jquery canvas 用户点击记录

    <div style="width:200px; height:20px; position:fixed; top:0; left:0; background-color:blue;& ...

  2. Bzoj1486/洛谷P3199 最小圈(0/1分数规划+spfa)/(动态规划+结论)

    题面 Bzoj 洛谷 题解(0/1分数规划+spfa) 考虑\(0/1\)分数规划,设当前枚举到的答案为\(ans\) 则我们要使(其中\(\forall b_i=1\)) \[ \frac{\sum ...

  3. 【leetcode】200. Number of Islands

    原题: Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is s ...

  4. [Nescafé41]编码病毒(循环卷积)

    题意看起来好麻烦实际上很简单,首先4s可以先bitset暴力一下,听说卡卡就能过:$O(2^{22}+n^2/32)$ #include<cstdio> #include<bitse ...

  5. [CODE FESTIVAL 2017]Full Tournament

    题意:$2^n$个编号为$1\cdots2^n$的人打比赛,这个比赛会给每个人一个唯一的排名,比赛规则递归地定义如下: $2^n$个人打的是级别为$n$的比赛,初始时他们按某种顺序站成一排 当$n=0 ...

  6. 【带权并查集】poj1182 食物链

    带权并查集,或者叫做种类并查集,经典题. http://blog.csdn.net/shuangde800/article/details/7974668 这份代码感觉是坠吼的. 我的代码是暴力分类讨 ...

  7. 【DFS】bzoj2435 [Noi2011]道路修建

    两遍DFS.第一遍统计以每个点为根的子树大小,第二遍更新答案. #include<cstdio> #include<iostream> using namespace std; ...

  8. React中的表单元素

    在web应用开发当中,表单还是很重要的元素. 应用表单组件有:文本框(input.textarea).单选按钮和复选框.Select组件. 文本框:文本框的状态改变即文本框中的内容的改变.此时的sta ...

  9. centos yum命令报错

    Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Could not retriev ...

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

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