溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

【SIP】OPEN API測試實(shí)戰(zhàn)源代碼

發(fā)布時(shí)間:2020-04-05 00:53:47 來源:網(wǎng)絡(luò) 閱讀:785 作者:elbertchen 欄目:軟件技術(shù)
    上篇文字介紹了如何利用正交驗(yàn)證法來實(shí)現(xiàn)測試用例的設(shè)計(jì)。本篇文章將針對上篇文章介紹代碼的實(shí)現(xiàn)。以授權(quán)用例一的Case4為例子。
    首先需要準(zhǔn)備測試數(shù)據(jù),本文使用的是DBUNIT。首先準(zhǔn)備xml文件如下:
 <SIP_API API_ID= "elbert_api00204" API_NAME ="alitest.ali-54-test204" ISP_ID = "elbert_isp001"
 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 APP_ID="test_app059" app_name="zcappname059" isv_id="001"
  app_no="test_app059" APP_SECRET="secret_app003" LEVEL_ID="alitest_level7"/>
 <App_Profile APP_ID= "test_app059" APP_NO="test_app059" App_Name="測試SIP59" CATEGORY_ID ="elber002"
  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="基本價(jià)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"
 />
 <SIP_APP_LEVEL LEVEL_ID="alitest_level7" LEVEL_NAME="阿里軟件測試級7" DEFAULT_ACCESS_FREQUENCY="3" DAY_ACCESS_COUNT="0" API_GROUPS="alitest_group3,alitest_group4"
  LEVEL_DESC="阿里軟件接口測試6" GMT_CREATE="2009-01-10 13:28:50" GMT_MODIFIED="2009-01-10 13:28:50"
 />
 <!-- API_GROUP_ID API_GROUP_NAME INCLUDE_APINAMES EXCLUDE_APINAMES INCLUDE_ISPS API_GROUP_DESC GMT_CREATE GMT_MODIFIED
alitest_group1 阿里軟件測試組一   elbert_isp001,elbert_isp002,elbert_isp003 阿里軟件5.3之前API集合 2009-1-10 2009-1-10
  -->
 <SIP_API_GROUP API_GROUP_ID="alitest_group3" API_GROUP_NAME="阿里軟件測試組二" INCLUDE_APINAMES="" EXCLUDE_APINAMES=""
 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"
 />
 <SIP_API_GROUP API_GROUP_ID="alitest_group4" API_GROUP_NAME="阿里軟件測試組二" INCLUDE_APINAMES="" EXCLUDE_APINAMES=""
 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的方法,載入數(shù)據(jù)。在實(shí)戰(zhàn)中這部分被分裝成loadData函數(shù)如下:
    loadCaseData("testCase4_CORE.xml",coreSchemaName);
然后實(shí)現(xiàn)測試的主要部分,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("數(shù)據(jù)準(zhǔn)備開始......");
  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("數(shù)據(jù)準(zhǔn)備完畢");
  // TODO Auto-generated constructor stub
 }
 public void TestCase(Map<String, String> 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字段為多個(gè)字段,且API在Group中
  * @throws Exception
  */
 @Test
 public void TestCase4() throws Exception {
  String sip_apiname = "alitest.ali-54-test204";
  //數(shù)據(jù)準(zhǔn)備
  String ExpXmlText = "not OK";
  String sip_appkey = "test_app059";
  TestCase(null,ExpXmlText,"9999",null, sip_apiname,sip_appkey);
 }
 
 
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI