本文连接:http://pengyusong.blog.51cto.com/blog/4893374/1317325
本文通过学习WebInject官网教材,然后测试自己开发的WebService。
首先,我们有一个无敌的HelloWorld服务,这个服务超级简单,相信大家都很熟悉。就不介绍了。
然后,创建SOAP消息,根据我自己的经验,soap消息就是把webservice的WSDL文件中的输入输出message给soap化了。具体看一个例子:
WSDL message格式:
<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中内容。
再然后就是测试用例文件:
<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就会执行成功。
------------------------------------------------------- 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
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/196943.html