Junit 编写测试用例测试WebService方法

1.编写测试用例

WebService方法参考

Java Axis2调用WebService接口异常解决方案

http://blog.csdn.net/u011270461/article/details/9796559

package com.xxx.webservice.axis;

import junit.framework.TestCase;

/**
 * @ClassName AxisClientUtilTest
 * @Description 针对特定的类编写测试用例
 * @Author weizhi
 * @Date 2013-8-6 下午02:36:14
 * 
 */

public class AxisClientUtilTestcase1 extends TestCase {

	private AxisClientUtil axisClient = null;
	/**
	 * @Title setUp
	 * @Description TODO
	 * @Author weizhi
	 * @param @throws java.lang.Exception
	 * @return void
	 * @throws
	 */
	protected void setUp() throws Exception {
		String url = "http://ip:7012/bill/services/businessService";
		axisClient = new AxisClientUtil(url);
	}

	/**
	 * @Title tearDown
	 * @Description TODO
	 * @Author weizhi
	 * @param @throws java.lang.Exception
	 * @return void
	 * @throws
	 */
	protected void tearDown() throws Exception {
	}

	/**
	 * Test method for
	 * {@link com.xxx.webservice.axis.AxisClientUtil#send(java.lang.String, java.lang.Object[])}
	 * .
	 */
	public void testSend() {
		// 入参1
		String in0 = "A00008|0770000001|V1.0|" + "127.0.0.1";
		StringBuffer in2 = new StringBuffer();

		in2.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		in2.append("<PayPlatRequestParameter>");
		in2.append("<CTRL-INFO WEBSVRNAME=\"手机号码验证\" WEBSVRCODE=\"A00008\" APPFROM=\"0990000002\" SERNUM=\"0000000000050560\" APPDATE=\"20130125\" APPTIME=\"081908\"/>");
		in2.append("<PARAMETERS>");
		in2.append("<BILLORGID>9999009999019004</BILLORGID>");
		in2.append("<ORDERID>1230000000050560</ORDERID>");
		in2.append("<PRODUCTNO>18916061686</PRODUCTNO>");
		in2.append("<TEXT1></TEXT1>");
		in2.append("<TEXT2></TEXT2>");
		in2.append("<TEXT3></TEXT3>");
		in2.append("<TEXT4></TEXT4>");
		in2.append("<TEXT5></TEXT5>");
		in2.append("</PARAMETERS>");
		in2.append("<MAC>1d79647694268a4d1a9ecad667ca5ae8</MAC>");
		in2.append("</PayPlatRequestParameter>");

		Object[] param = new Object[]{in0, in2.toString()};

		// 要请求的WebService服务的方法名字
		String method = "dispatchCommand";

		String result = axisClient.send(method, param);
		
		//对比测试结果
		assertEquals("0000", result);

	}

}

package com.xxx.webservice.axis;

import junit.framework.Test;
import junit.framework.TestSuite;

/**
 * @ClassName AllTests
 * @Description 汇集所有测试用例
 * @Author weizhi 
 * @Date 2013-8-6 下午08:07:54 
 *
 */

public class AxisClientUtilAllTests {

	public static Test suite() {
		TestSuite suite = new TestSuite("Test for com.xxx.webservice.axis");
		//$JUnit-BEGIN$
		suite.addTestSuite(AxisClientUtilTestcase1.class);
		suite.addTestSuite(AxisClientUtilTestcase2.class);
		//$JUnit-END$
		return suite;
	}
}


package com.xxx.webservice.axis;

/**
 * @ClassName TestUi
 * @Description 测试用例统计
 * @Author weizhi
 * @Date 2013-8-6 下午08:16:49 
 *
 */

public class TestUiStart {

	/** 
	 * @Title main 
	 * 
	 * @Description 主应用程序入口
	 * @Author weizhi
	 * @param @param args     
	 * @return void     
	 * @throws 
	 */

	public static void main(String[] args) {
		//测试结果面板显示
		junit.textui.TestRunner.run(AxisClientUtilAllTests.suite());
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值