使用WebInject测试WebService

本文通过学习 WebInject官网教材,然后 测试自己开发的WebService。
  首先,我们有一个无敌的HelloWorld服务,这个服务超级简单,相信大家都很熟悉。就不介绍了。
  然后,创建SOAP消息,根据我自己的经验,soap消息就是把webservice的WSDL文件中的输入输出message给soap化了。具体看一个例子:
  WSDLmessage格式:
  <wsdl:messagename="sayHelloRequest">
  <wsdl:partname="parameters"element="ns:sayHello"/>
  </wsdl:message>
  sayHello元素的格式:
  <xs:elementname="sayHello">
  <xs:complexType>
  <xs:sequence>
  <xs:elementminOccurs="0"name="args0"nillable="true"type="xs:string"/>
  </xs:sequence>
  </xs:complexType>
  </xs:element>
  转成soap消息格式就是:
<?xmlversion='1.0'encoding='UTF-8'?>
<soapenv:Envelopexmlns: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中内容。
  再然后就是 测试用例文件:
<testcasesrepeat="1">
<case
id="1"
description1="WebServicesSample-HelloWorld"
url="http://localhost:8080/axis2/services/HelloWorld?wsdl"
method="post"
posttype="text/xml"
postbody="file=>doGoogleSearch.xml"
verifypositive="\<return>Hello,mynameispengyusong\</return>"
/>
</testcases>
最后在执行这个测试用例:通过GUI方式的话,在config.xml文件中指定我们的测试用例文件即可。然后在GUI界面点击Run就会执行成功。
-------------------------------------------------------
Test:test_google.xml-1
WebServicesSample-GoogleSearchAPI
Verify:"Hello,mynameispengyusong"
PassedXMLParser(contentiswell-formed)
PassedPositiveVerification
PassedHTTPResponseCodeVerification(notinerrorrange)
TESTCASEPASSED
ResponseTime=0.015sec
-------------------------------------------------------
StartTime:WedOct3016:46:342013
TotalRunTime:0.409seconds
TestCasesRun:1
TestCasesPassed:1
TestCasesFailed:0
VerificationsPassed:3
VerificationsFailed:0
AverageResponseTime:0.015seconds
MaxResponseTime:0.015seconds
MinResponseTime:0.015seconds

最新内容请见作者的GitHub页:http://qaseven.github.io/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值