接口的测试方法

上传人:大米 文档编号:563654846 上传时间:2023-06-11 格式:DOCX 页数:6 大小:101.14KB
返回 下载 相关 举报
接口的测试方法_第1页
第1页 / 共6页
接口的测试方法_第2页
第2页 / 共6页
接口的测试方法_第3页
第3页 / 共6页
接口的测试方法_第4页
第4页 / 共6页
接口的测试方法_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《接口的测试方法》由会员分享,可在线阅读,更多相关《接口的测试方法(6页珍藏版)》请在金锄头文库上搜索。

1、【WebService】接口的测试方法有以下多种方式:一、通过 WSCaller.jar 工具进行测试:前提:知道 wsdl 的 url。wsCaller 可执行程序的发布方式为一个 wsCaller.jar 包,不包含 Java 运行环境。你可以把wsCaller.jar复制到任何安装了 Java运行环境(要求安装JRE/JDK 1.3.1或更高版本)的计 算机中,用以下命令运行 wsCaller:java -jar wsCaller.jar使用wsCaller软件的方法非常简单,下面是wsCaller的主界面:vsCalljer 一 A Si.ft.pleSeEvj ceesterWSBL

2、LOTatlon:Ifwok首先在WSDL Location输入框中输入你想调用或想测试的Web Service的WSDL位置,如 “http:/ 然 后 点 “Find” 按 钮 。 wsCaller就会检查你输入的URL地址,并获取Web Service的WSDL信息。如果信息获取 成功, wsCaller 会在 Service 和 Operation 下拉列表框中列出该位置提供的 Web Service 服 务和服务中的所有可调用的方法。你可以在列表框中选择你要调用或测试的方法名称, 选定后, wsCaller 窗口中间的参数列表框就会列出该方法的所有参数,包括每个参数的名称、类型和参数

3、值的输入框(只对IN或IN, OUT 型的参数提供输入框)。你可以输入每个 参数的取值。如下图:satfHe-itcwSDLLDcatlan:hfft pesile.co nVaxi sfHelloTpe:护J stringvskue: meParameter 1: messagevakie: nsiioTvue: IN mlParameter 7: (imesValue: 3伽蹄她1: namavsCller - A Si&ple Veb Sezvic:terHtv谕w Ti阿甲取1叶0寤这时,如果你想调用该方法并查看其结果的话,只要点下面的“Invoke”按钮就可以了。如 果你想测试该方法

4、的执行时间,则可以在“Invoke Times框中指定重复调用的次数,然后 再按“Invoke”按钮。wsCaller会自动调用你指定的方法,如果调用成功,wsCaller会显示结 果对话框,其中包括调用该方法所花的总时间,每次调用的平均时间和该方法的返回值 (包括返回值和所有输出型的参数)。如下图:wsCaller 软件是基于 Axis 库(Apache extensible Interaction System)开发的,Axis 库的介绍 及其版权信息请参见 Apache Software Foundation 的网站 http:/www.apache.org/。二、编写java的Main

5、 ()函数,创建XFireProxyFactory调用声明的Interface接口函数。 前提:知道wsdl的url、知道webservice程序的接口(方法)声明。举例:public static void main(String args) Service srvcModel = new ObjectServiceFactory().create(IHelloWorldService.class);XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire();String he

6、lloWorldURL = http:/99.48.225.100:9999/WS/services/HelloWorldService;try IHelloWorldService srvc = (IHelloWorldService) factory.create(srvcModel, helloWorldURL);System.out.print(srvc.example(dennis); catch (MalformedURLException e) e.printStackTrace();三、利用Eclipse向导生成webservice的客户端调用程序。前提:知道wsdl的url、

7、知道webservice程序的接口(方法)声明。步骤:1) 在Eclipse中加入Xfire插件:在Eclipse的安装目录的plugins下包含:org.codehaus.xfire.eclipse.ui_1.0.2.xfire126.jar、org.codehaus.xfire.eclipse.ui.wizards_1.0.2.xfire126.jar、org.codehaus.xfire.eclipse.core_1.0.2.xfire126.jar在Eclipse的安装目录的features下包含:org.codehaus.xfire.eclipse_1.0.2.xfire1262)

8、在Eclipse中创建一个 Web Project项目,设为WSCIient项目名。同时点击项目右键,添加 Xfire nature。3) 在 WSClient 项目下创建一个 Web Service Client 文件组【或者是 Code Generation fromWSDL document 的文件组!】。即点击项目右键, new-other-.输入 webservice 的 url,比如:http:/localhost:9999/WS/services/HelloWorldService?wsdl再选好生成文件放置目录。完成生成!4) 修改所生成文件组中的文件: *client.jav

9、a 中的 main 函数.比如:生成的文件为BizRemoteServiceClient.java,在main函数中找到:client.getBizRemoteServiceSoapLocalEndpoint();该语句用 BizRemoteServiceSoap bizRemoteServiceSoap = client.getBizRemoteServiceSoap(); 代替即可!public static void main(String args) BizRemoteServiceClient client = new BizRemoteServiceClient();/create

10、 a default service endpoint/BizRemoteServiceSoap bizRemoteServiceSoap = client.getBizRemoteServiceSoapLocalEndpoint();BizRemoteServiceSoap bizRemoteServiceSoap = client.getBizRemoteServiceSoap();/TODO: Add custom client code here/bizRemoteServiceSoap.yourServiceOperationHere();MyResponse MyResponse=bizRemoteServiceSoap.login(ivy1, 111);System.out.println(MyResponse.getFlag();System.out.println(MyResponse.getDetail();System.out.println(test client completed);System.exit(0);绿色代码部分是根据测试业务逻辑加入的测试代码!试具体测试任务而定!直接运行该 main 函数,看结果即可!

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号