温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用WebInject测试WebService

发布时间:2020-08-02 04:10:21 来源:网络 阅读:691 作者:pengyusong2012 栏目:软件技术

本文连接: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



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI