博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TestNG+Jenkins+Maven参数化测试dubbo接口
阅读量:5343 次
发布时间:2019-06-15

本文共 6672 字,大约阅读时间需要 22 分钟。

1.TestNG参数化测试用例:

package com.tree.autotest.testcase.IUserBankSummaryService; import com.datatrees.finance.risk.dataclean.service.IUserBankSummaryService; 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/3/6.  */ public class TestGetBankIdsOfNeedMoreBill extends BaseTestNGTest {
@Autowired private IUserBankSummaryService iUserBankSummaryService; private boolean handleOk; private String insertSql; private static String excel; private static Map allCases; private Integer testuser; private TestCase testcase; @BeforeMethod public void setUp() throws SQLException {
//获取excel用例列表 handleOk = true; testcase = CommonUtil_2.getTestCaseBean(allCases, "case1", "case1-1"); testuser = Integer.valueOf(testcase.param1); //获取SQL insertSql = testcase.stepSql; //删除,添加数据 handleOk &= deleteData(testuser); handleOk &= ManagedSqlUtil.insertBySql(insertSql, DBIdConstant.MySql_Basisdata_ID); System.out.println("----->> @BeforeClass is finished"); } @DataProvider(name = "testData") private static Object[][] dataprovide()throws IOException {
excel="src/main/resources/case/IUserBankSummaryService/TestGetBankIdsOfNeedMoreBill.xlsx"; allCases = CommonUtil_2.getAllCases(excel); System.out.println("dataprovide方法执行"); Object[][] testData = ExcelHandle.readXlsx(excel, "用例列表"); return testData; } @Test(dataProvider="testData") public void test_case_1(HashMap
map) throws Exception {
testuser =Integer.valueOf(map.get("userid")); //实际值: List
actual_list = iUserBankSummaryService.getBankIdsOfNeedMoreBill(testuser); //预期值: List
excepted_list = get_excepted_list(testuser); //验证: System.out.println("userId值:"+testuser); System.out.println("actual_list值:"+actual_list.toString()); System.out.println("excepted_list值:"+excepted_list.toString()); System.out.println("size值:"+excepted_list.size()); if (excepted_list.size()==0){
Assert.assertEquals(actual_list.toString(), "[]"); }else {
Assert.assertEquals(actual_list.toString(), excepted_list.toString()); } System.out.println("----->> @Test is finished"); } @AfterMethod public void tearDown() {
testuser = Integer.valueOf(testcase.param1); handleOk &= deleteData(testuser); System.out.println("----->> AfterClass is finished"); } //定义数据清理 public boolean deleteData(Integer userid) {
String deleteSql = "delete from t_user_bank_summary where userid = "+userid+";"; handleOk &= ManagedSqlUtil.deleteBySql(deleteSql, DBIdConstant.MySql_Basisdata_ID); return handleOk; } //预期值 public List
get_excepted_list(Integer userid)throws SQLException{
String searchSql = " SELECT a.BankId " + " FROM t_user_bank_summary a, (SELECT MAX(Id) mid " + " FROM t_user_bank_summary " + " WHERE UserId ="+userid+" " + " GROUP BY BankId) t " + " WHERE a.id = t.mid AND EffectiveBillCount12M<11"; ResultSet rs = ManagedSqlUtil.selectBySql(searchSql,DBIdConstant.MySql_Basisdata_ID); List
list = new ArrayList
(); while (rs.next()){ list.add(rs.getInt(1)); } return list; } } 2.test suite配置:
3.Pom.xml设置需运行的testng.xml文件路径和依赖: 配置插件:
org.apache.maven.plugins
maven-surefire-plugin
2.6
true
src/main/java/com/tree/autotest/testsuite/testng.xml
usedefaultlisteners
false
listener
org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter
target/
always
配置POM.xml testNG相关依赖
org.testng
testng
6.4
org.uncommons
reportng
1.1.4
test
org.testng
testng
com.google.inject
guice
3.0
test
4.maven环境变量: vi .bash_profile

export JAVA_HOME=/aliyun/server/java

export JRE_HOME=/aliyun/server/java/jre

export CLASSPATH=/aliyun/server/java/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib:$JRE_HOME/lib:.:$CLASSPATH

export PATH=/aliyun/server/mysql/bin:/dashu/software/apache-maven-3.39/bin:/aliyun/server/nginx/sbin:$JAVA_HOME/bin:$PATH

5.maven执行测试:

maven clean test

6.Jenkins配置:

安装TestNG插件

git:http://192.168.5.252/testgroup/risk-dataclean-test.git

Shell:

export JAVA_HOME=/aliyun/server/java

export JRE_HOME=/aliyun/server/java/jre
export CLASSPATH=/aliyun/server/java/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib:$JRE_HOME/lib:.:$CLASSPATH
export PATH=/aliyun/server/mysql/bin:/dashu/software/apache-maven-3.39/bin:/aliyun/server/nginx/sbin:$JAVA_HOME/bin:$PATH
mvn clean test

TestNG Report:

**/testng-results.xml

 

7.html报告文件:

 

 

 

 

转载于:https://www.cnblogs.com/ceshi2016/p/6527284.html

你可能感兴趣的文章
Linux 的基本操作(文件与目录管理)
查看>>
LeetCode 9. Palindrome Number
查看>>
python——排序
查看>>
同时使用Binding&StringFormat 显示Text【项目】
查看>>
过拟合与欠拟合 之原因和解决方法
查看>>
线段树+差分【p1438】无聊的数列
查看>>
关于deepin上谷歌浏览器会出现延时的问题
查看>>
Mobility Express部署外部镜像服务器
查看>>
关于Mobility Express转LAP注意事项
查看>>
web前端经典小题
查看>>
AutoCAD如何倒角 倒圆角 倒直角
查看>>
Office PPT中如何插入flash
查看>>
C# Fade Form Effect With the AnimateWindow API Function
查看>>
golang多维数组的切片
查看>>
IP 网际协议
查看>>
C语言_第五章__实践(密码转换)
查看>>
docker 容器后台运行命令
查看>>
jquery 获取css position的值
查看>>
面向对象的程序设计
查看>>
a标签添加点击事件
查看>>