|
上篇文字介绍了如何利用正交验证法来实现测试用例的设计。本篇文章将针对上篇文章介绍代码的实现。以授权用例一的Case4为例子。
首先需要准备测试数据,本文使用的是DBUNIT。首先准备xml文件如下:
然后利用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);
}
|
|
|