package org.test;
package org.test;
import junit.swingui.TestRunner;
public class Add {
public int add(int a,int b){
return a+b;
}
public static void main(String[] args){
TestRunner runner = new TestRunner();
runner.run(AddTest.class);
}
}
package org.test;
import junit.framework.Assert;
import junit.framework.TestCase;
public class AddTest extends TestCase {
private Add add = null;
@Override
protected void setUp() throws Exception {
add = new Add();
}
/**满足条件
* 1)必须是public
* 2)必须是void
* 3)必须以test开头
* 4)必须无参数
*/
public void testAdd(){
int result = add.add(3, 5);
Assert.assertEquals(8, result);
}
}
package org.test;
public class Divide {
public int divide(int a,int b) throws Exception{
if(0 == b){
throw new Exception("除数不能为0");
}
return a/b;
}
}
package org.test;
import junit.framework.Assert;
import junit.framework.TestCase;
public class DivideTest extends TestCase {
private Divide divide = null;
@Override
protected void setUp() throws Exception {
divide = new Divide();
}
/**满足条件
* 1)必须是public
* 2)必须是void
* 3)必须以test开头
* 4)必须无参数
*/
public void testDivide(){
int result = 0;
try {
result = divide.divide(10, 2);
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertEquals(5, result);
}
public void testDivide0(){
Throwable tx = null;
try {
int result = divide.divide(10, 0);
Assert.fail();//"出错了"的意思
} catch (Exception e) {
tx = e;
}
Assert.assertNotNull(tx);
Assert.assertEquals(Exception.class, tx.getClass());
Assert.assertEquals("除数不能为0", tx.getMessage());
}
}
package org.test;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class TestAll extends TestCase {
/**
* 方法必须这样写
* @return
*/
public static Test suite(){
TestSuite suite = new TestSuite();
suite.addTestSuite(DivideTest.class);
suite.addTestSuite(AddTest.class);
return suite;
}
}
分享到:
相关推荐
junit3.8jar以及源码以及测试案例详解下载
Junit3.8 API CHM Junit3.8 API CHM Junit3.8 API CHM Junit3.8 API CHM Junit3.8 API CHM
NULL 博文链接:https://zhouwendong006.iteye.com/blog/372795
junit3.8 和junit4 api
NULL 博文链接:https://vincent-yy.iteye.com/blog/358388
Junit 3.8 详解 解压后生成.exe文件,可直接播放。
JUnit3.8 与 Ant1.6教程。 经过繁转简和相关术语习惯修改。文件格式为doc。
浪曦][原创]Junit.3.8.详解续二.rar
NULL 博文链接:https://myhongkongzhen.iteye.com/blog/447447
Junit3.8.2的包 测试用的 为什么非要20个字?
JUnit3.8.1 jar包
包括了Junit 4.4和3.8.1的所有源码及帮助文档,有助于深入学习 junit
junit3.8.1.rar JAVA编译,测试工具
junit-3.8.1.jar资源,有需要的可以下载,下载,下载,下载
JAVA测试-----Junit.3.8.part3
JAVA测试------Junit.3.8.part1
JAVA测试----------Junit.3.8.part2
自己搜集和总结的,比较适合新手学习,涉及JUnit3.8和JUnit4.x有区别的地方
JAVAEE5API.chm J2EE_API.chm JavaDoc6API.CHM ...JUNIT3.8API.chm struts 1.3 api.chm XMLHTTP手册.CHM 网页制作完全手册.chm 由于上传权限问题 暂时只能上传这么多希望对大家有用 如有别的需要 联系本人
浪曦][原创]Junit.3.8.详解续一.rar