在SoapUI中可以定義一個(gè)個(gè)的測試用例TestCase,但是有些用例是依賴于之前的用例的,如果純拷貝的話可能會導(dǎo)致用例比較臃腫而且不好維護(hù),比如說存在如下兩個(gè)TestCase:
1)CreateUserTestCase:測試創(chuàng)建用戶,通過發(fā)送Soap報(bào)文方式創(chuàng)建用戶同時(shí)需要校驗(yàn)
數(shù)據(jù)庫中值是否正確
2)ChangUserInfoTestCase:測試修改用戶信息,通過發(fā)送Soap報(bào)文方式修改用戶信息,需要校驗(yàn)修改前和修改后的用戶信息
ChangUserInfo之前必須得創(chuàng)建一個(gè)用戶,純拷貝肯定是不可取的,因?yàn)楹罄m(xù)如果創(chuàng)建用戶的接口稍有變動(dòng),則需要同時(shí)在ChangUserInfoTestCase和CreateUserTestCase修改請求報(bào)文。
SoapUI在TestCase中提供Run TestCase的Step,可以直接調(diào)用指定的TestCase,但是需要前一個(gè)TestCase中將屬性傳遞出來,步驟如下:
1)在被調(diào)用TestCase中設(shè)置返回屬性
testRunner.testCase.setPropertyValue("屬性名稱",“屬性值”)
2)在調(diào)用TestCase中增加Run TestCase指向被調(diào)用TestCase
3)在調(diào)用TestCase中的其它
Test Step中獲取屬性
例如:在CreateUserTestCase中將創(chuàng)建好的用戶ID傳給ChangUserInfoTestCase,則步驟如下:
1)在CreateUserTestCase中通過Groovy Script. 設(shè)置返回屬性:
testRunner.testCase.setPropertyValue("UserID",context.getProperty("UserID"))
2) 在ChangUserInfoTestCase中增加Run TestCase:RunNewUserTestCase指向CreateUserTestCase并指定UserID屬性為輸入值
3)在ChangUserInfoTestCase中獲取執(zhí)行CreateUserTestCase得到的用戶ID
def NewUserProperties = testRunner.testCase.getTestStepByName( "RunNewUserTestCase" ); log.info(NewUserProperties .getPropertyValue( "UserID" )) |
本文出自 wendy-qian 的51Testing軟件測試博客:http://www.51testing.com/?15017055