需要在工程中引入junit的jar包,测试sum方法的返回值是否正确,代码如下:
package com.channelsoft.cmmb.cspapi.webservice;
import junit.framework.TestCase;
public class TestCalculator extends TestCase {
public int sum(int a,int b){
return (a+b);
}
public void testAdd(){
int c = sum(1,2);
// 3 是期待数值
assertEquals(3,c);
}
}
运行
[img]http://dl.iteye.com/upload/attachment/0074/5056/ac27add6-a2b2-3c88-811b-33c55fca9f07.png[/img]
结果如下
[img]http://dl.iteye.com/upload/attachment/0074/5058/72284750-cb88-3929-a756-e6b69b8d2978.png[/img]
如果不是绿色,那边右边会显示出错的行数等相关信息
package com.channelsoft.cmmb.cspapi.webservice;
import junit.framework.TestCase;
public class TestCalculator extends TestCase {
public int sum(int a,int b){
return (a+b);
}
public void testAdd(){
int c = sum(1,2);
// 3 是期待数值
assertEquals(3,c);
}
}
运行
[img]http://dl.iteye.com/upload/attachment/0074/5056/ac27add6-a2b2-3c88-811b-33c55fca9f07.png[/img]
结果如下
[img]http://dl.iteye.com/upload/attachment/0074/5058/72284750-cb88-3929-a756-e6b69b8d2978.png[/img]
如果不是绿色,那边右边会显示出错的行数等相关信息