本文鏈接:http://pengyusong.blog.51cto.com/blog/4893374/1317325html
本文經過學習WebInject官網教材,而後測試本身開發的WebService。web
首先,咱們有一個無敵的HelloWorld服務,這個服務超級簡單,相信你們都很熟悉。就不介紹了。apache
而後,建立SOAP消息,根據我本身的經驗,soap消息就是把webservice的WSDL文件中的輸入輸出message給soap化了。具體看一個例子:ide
WSDL message格式:post
<wsdl:message name="sayHelloRequest"> <wsdl:part name="parameters" element="ns:sayHello"/> </wsdl:message>
sayHello元素的格式:學習
<xs:element name="sayHello"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="args0" nillable="true" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
轉成soap消息格式就是:測試
<?xml version='1.0' encoding='UTF-8'?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://ws.apache.org/axis2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <q0:sayHello> <args0>pengyusong</args0> </q0:sayHello> </soapenv:Body> </soapenv:Envelope>
能夠看到soap消息就是把message中的part解析爲soap中的body中內容。google
再而後就是測試用例文件:url
<testcases repeat="1"> <case id="1" description1="Web Services Sample - Hello World" url="http://localhost:8080/axis2/services/HelloWorld?wsdl" method="post" posttype="text/xml" postbody="file=>doGoogleSearch.xml" verifypositive="\<return>Hello, my name is pengyusong\</return>" /> </testcases>
最後在執行這個測試用例:經過GUI方式的話,在config.xml文件中指定咱們的測試用例文件便可。而後在GUI界面點擊Run就會執行成功。spa
------------------------------------------------------- Test: test_google.xml - 1 Web Services Sample - Google Search API Verify : "Hello, my name is pengyusong" Passed XML Parser (content is well-formed) Passed Positive Verification Passed HTTP Response Code Verification (not in error range) TEST CASE PASSED Response Time = 0.015 sec ------------------------------------------------------- Start Time: Wed Oct 30 16:46:34 2013 Total Run Time: 0.409 seconds Test Cases Run: 1 Test Cases Passed: 1 Test Cases Failed: 0 Verifications Passed: 3 Verifications Failed: 0 Average Response Time: 0.015 seconds Max Response Time: 0.015 seconds Min Response Time: 0.015 seconds