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());
	}

}

你可能感兴趣的:(JUnit)