<h5>測(cè)試接口用例結(jié)構(gòu)</h5>
-
DataSource 設(shè)置數(shù)據(jù)源來源于寫好的excle屹耐,作為后續(xù)請(qǐng)求和期望結(jié)果的數(shù)據(jù)源
Paste_Image.png
2.http請(qǐng)求,post形式,按照接口參數(shù)格式傳參,注按照接口意請(qǐng)求參數(shù)格式傳參
3.用soapui的groovy腳本校驗(yàn)請(qǐng)求與返回結(jié)果脖律,并將結(jié)果傳到下個(gè)請(qǐng)求 dataSink里面
腳本如下:
<pre>
def testResult = context.expand( '${xxxxxx#Response#//xxx_response[1]/xx[1]/xxx[1]}' )
def hopeResult = context.expand( '${DataSource#hope_result}' )
def rslt = NewTrade.checkResult( testResult, hopeResult )
testRunner.testCase.testSteps["DataSink"].setPropertyValue("result",rslt)
testRunner.testCase.testSteps["DataSink"].setPropertyValue("hopeResult",hopeResult)
</br>
//檢查實(shí)際結(jié)果與預(yù)期結(jié)果是否相等
def static String checkResult( String testResult,String hopeResult ) {
//判斷測(cè)試結(jié)果
if( testResult == hopeResult )
{
//符合預(yù)期結(jié)果,或者返回固定的錯(cuò)誤消息
//log.info "testResult: " + testResult
return "OK"
}
else if( testResult.contains("XXX") //header部分的檢查,只抽取錯(cuò)誤碼開始的部分
|| testResult.contains("XXXX") //header部分的檢查,只抽取錯(cuò)誤碼開始的部分
)
{
return "XXX XXXX ERROR"
}
else
{
return "NG"
}
}
}
</pre>
4.dataSink 記錄需要的輸出結(jié)果
5.DataSourceLoop設(shè)置循環(huán)的數(shù)據(jù)源和步驟腕侄,達(dá)到下個(gè)請(qǐng)求調(diào)用下一組數(shù)據(jù)小泉,以此達(dá)到真正的接口自動(dòng)化測(cè)試
---------------------------至此,一個(gè)帶有圖片信息的接口自動(dòng)化測(cè)試就完成了--------------------------