【SIP】OPEN API测试实战源代码
发表于:2024-10-19 作者:千家信息网编辑
千家信息网最后更新 2024年10月19日,上篇文字介绍了如何利用正交验证法来实现测试用例的设计。本篇文章将针对上篇文章介绍代码的实现。以授权用例一的Case4为例子。 首先需要准备测试数据,本文使用的是DBUNIT。首先准备xml文件如下:
千家信息网最后更新 2024年10月19日【SIP】OPEN API测试实战源代码上篇文字介绍了如何利用正交验证法来实现测试用例的设计。本篇文章将针对上篇文章介绍代码的实现。以授权用例一的Case4为例子。 首先需要准备测试数据,本文使用的是DBUNIT。首先准备xml文件如下: CONTROL_LEVEL = "1" API_URL = "http://apitest.alisoft.com:8080/isp-test/login" REQUIRE_TOKEN_TYPE ="0"
REQUIRE_TIMEOUT = "1000" STATUS = "0" API_TEST_URL ="http://apitest.alisoft.com:8080/isp-test/login"
FREQUENCY_VALVE = "6" API_TYPE ="0"
/>
app_no="test_app059" APP_SECRET="secret_app003" LEVEL_ID="alitest_level7"/>
ISV_ID="4082604" Status ="0" SUBSCRIBED_COUNT="0" AUTO_SIGN_ON_URL="http://www.sina.com.cn"
SERVICE_SCOPE = "1" GMT_CREATE ="2008-2-19 13:28:50" GMT_MODIFIED = "2008-2-19 13:28:50"
CREATOR = "1" MODIFIER ="1" IS_DELETED ="n" DESCRIPTION="测试部专用" STANDARD_PRICE="基本价12"
GMT_SERVICE_END="2009-12-19 13:28:50" PRICE_MODE="m" PRICE_URL="http://mall.alisoft.com/apps/shopwindow/appSubscibeAction!showSubscAppModel.jspa"
PRICE_CALC_CLASS="modelPriceService" LICENCE_NUM="100"
/>
LEVEL_DESC="阿里软件接口测试6" GMT_CREATE="2009-01-10 13:28:50" GMT_MODIFIED="2009-01-10 13:28:50"
/>
INCLUDE_ISPS="elbert_isp002,elbert_isp003" API_GROUP_DESC="阿里软件5.4API集合1" GMT_CREATE="2009-1-11 01:01:01" GMT_MODIFIED="2009-1-11 01:01:01"
/>
INCLUDE_ISPS="elbert_isp001" API_GROUP_DESC="阿里软件5.4API集合1" GMT_CREATE="2009-1-11 01:01:01" GMT_MODIFIED="2009-1-11 01:01:01"
/> 然后利用DBUNIT的方法,载入数据。在实战中这部分被分装成loadData函数如下: loadCaseData("testCase4_CORE.xml",coreSchemaName); 然后实现测试的主要部分,JUNIT编码的工作。代码如下: public class TestApiGroups extends TestBaseWS {
private static String udbSchemaName;
private static String coreSchemaName;
private String api_server = "http://10.2.226.19:8180/sip/rest";
static String mysql_url = "jdbc:mysql://10.2.226.19:3306/sip";
private String dir = "com\\alisoft\\aep\\sip\\core54";
public TestApiGroups() throws Exception {
super();
db = util.DBConnection.getDbUnit();
udbSchemaName = util.DBConnection.schemaMap.get("UDB");
coreSchemaName = util.DBConnection.schemaMap.get("CORE");
System.out.println("数据准备开始......");
loadCaseData("testCase2_CORE.xml",coreSchemaName);
loadCaseData("testCase3_CORE.xml",coreSchemaName);
loadCaseData("testCase4_CORE.xml",coreSchemaName);
loadCaseData("testCase5_CORE.xml",coreSchemaName);
loadCaseData("testCase6_CORE.xml",coreSchemaName);
util.SIPHelp.Crush_Sip();
System.out.println("数据准备完毕");
// TODO Auto-generated constructor stub
}
public void TestCase(Map map, String ExpXmlText,String EXPSTATUES,String EXPERROR,String sip_apiname,String AppKey)
throws Exception {
String sip_appkey =AppKey;// "test_app003";// app_id
String sip_appsecret = "secret_app003";
String sessionid = "123456789";
String url = util.SIPHelp.prepareUrl(sip_appkey, sip_apiname, sip_appsecret,
api_server, sessionid,map);
System.out.println(url);
WebConversation conversation = new WebConversation();
WebRequest request = new PostMethodWebRequest(url);
WebResponse response = conversation.getResponse(request);
String ActStatus = response.getHeaderField("sip_status");
String ActError = response.getHeaderField("sip_error_message");
System.out.println(ActStatus);
assertEquals(EXPSTATUES, ActStatus);
if (EXPSTATUES.equals("9999"))
{ assertEquals(null, ActError); }
else
{
assertEquals(EXPERROR, ActError);
}
String ActXmlTest = response.getText();
System.out.println(ActXmlTest);
assertEquals(ExpXmlText, ActXmlTest);
} /**
* SIP_APP_LEVEL中含API_GROUPS字段为多个字段,且API在Group中
* @throws Exception
*/
@Test
public void TestCase4() throws Exception {
String sip_apiname = "alitest.ali-54-test204";
//数据准备
String ExpXmlText = "not OK";
String sip_appkey = "test_app059";
TestCase(null,ExpXmlText,"9999",null, sip_apiname,sip_appkey);
}
REQUIRE_TIMEOUT = "1000" STATUS = "0" API_TEST_URL ="http://apitest.alisoft.com:8080/isp-test/login"
FREQUENCY_VALVE = "6" API_TYPE ="0"
/>
SERVICE_SCOPE = "1" GMT_CREATE ="2008-2-19 13:28:50" GMT_MODIFIED = "2008-2-19 13:28:50"
CREATOR = "1" MODIFIER ="1" IS_DELETED ="n" DESCRIPTION="测试部专用" STANDARD_PRICE="基本价12"
GMT_SERVICE_END="2009-12-19 13:28:50" PRICE_MODE="m" PRICE_URL="http://mall.alisoft.com/apps/shopwindow/appSubscibeAction!showSubscAppModel.jspa"
PRICE_CALC_CLASS="modelPriceService" LICENCE_NUM="100"
/>
/>
/>
/> 然后利用DBUNIT的方法,载入数据。在实战中这部分被分装成loadData函数如下: loadCaseData("testCase4_CORE.xml",coreSchemaName); 然后实现测试的主要部分,JUNIT编码的工作。代码如下: public class TestApiGroups extends TestBaseWS {
private static String udbSchemaName;
private static String coreSchemaName;
private String api_server = "http://10.2.226.19:8180/sip/rest";
static String mysql_url = "jdbc:mysql://10.2.226.19:3306/sip";
private String dir = "com\\alisoft\\aep\\sip\\core54";
public TestApiGroups() throws Exception {
super();
db = util.DBConnection.getDbUnit();
udbSchemaName = util.DBConnection.schemaMap.get("UDB");
coreSchemaName = util.DBConnection.schemaMap.get("CORE");
System.out.println("数据准备开始......");
loadCaseData("testCase2_CORE.xml",coreSchemaName);
loadCaseData("testCase3_CORE.xml",coreSchemaName);
loadCaseData("testCase4_CORE.xml",coreSchemaName);
loadCaseData("testCase5_CORE.xml",coreSchemaName);
loadCaseData("testCase6_CORE.xml",coreSchemaName);
util.SIPHelp.Crush_Sip();
System.out.println("数据准备完毕");
// TODO Auto-generated constructor stub
}
public void TestCase(Map
throws Exception {
String sip_appkey =AppKey;// "test_app003";// app_id
String sip_appsecret = "secret_app003";
String sessionid = "123456789";
String url = util.SIPHelp.prepareUrl(sip_appkey, sip_apiname, sip_appsecret,
api_server, sessionid,map);
System.out.println(url);
WebConversation conversation = new WebConversation();
WebRequest request = new PostMethodWebRequest(url);
WebResponse response = conversation.getResponse(request);
String ActStatus = response.getHeaderField("sip_status");
String ActError = response.getHeaderField("sip_error_message");
System.out.println(ActStatus);
assertEquals(EXPSTATUES, ActStatus);
if (EXPSTATUES.equals("9999"))
{ assertEquals(null, ActError); }
else
{
assertEquals(EXPERROR, ActError);
}
String ActXmlTest = response.getText();
System.out.println(ActXmlTest);
assertEquals(ExpXmlText, ActXmlTest);
} /**
* SIP_APP_LEVEL中含API_GROUPS字段为多个字段,且API在Group中
* @throws Exception
*/
@Test
public void TestCase4() throws Exception {
String sip_apiname = "alitest.ali-54-test204";
//数据准备
String ExpXmlText = "not OK";
String sip_appkey = "test_app059";
TestCase(null,ExpXmlText,"9999",null, sip_apiname,sip_appkey);
}
测试
软件
阿里
数据
准备
软件测试
上篇
代码
字段
文章
实战
例子
函数
多个
接口
文件
文字
方法
正交
编码
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
服务器安全狗 小红伞引擎
小学生简单网络安全知识题库
网络安全责任工作情况报告
联想服务器更换硬盘
焦作bim软件开发工程拿证快
数据库应用最新发展的方向
数据库派符号是什么意思
岸电网络安全
江西省网络安全公开课
数据库中规范化
竞猜足球软件开发
中文网络安全信息
重庆静观服务器
网络安全责任中国人寿
北仑软件开发科技公司
软件开发网络图单代号
网络安全周以后怎么做
服务器ups不间断电源制作
数据库中怎么合并表
乌鲁木齐服务器哪家好
网络安全会议后的影响
去哪里可以学习网络技术
为什么前端开始要求连接数据库
列车时刻数据库
潜度网络技术有限公司
吕梁教育网络安全作业
370服务器
网站和数据库连接
nginx 服务器ip
推荐最好的服务器