[标题]:[转]JUnit4.5 QuickTutorial
[时间]:2009-7-5
[摘要]:JUnit官方例子QuickTutorial
[关键字]:JUnit、Test、测试、单元测试、helloworld
[环境]:JUnit4.5、MyEclipse7
[作者]:Winty (wintys@gmail.com) http://www.blogjava.net/wintys
[正文]:
Subscription.java:
package wintys.junit;
/**
* JUnit4.5 QuickTutorial
* http://code.google.com/p/t2framework/wiki/JUnitQuickTutorial
*
* @author Winty
* @version 2009-07-04
*/
public class Subscription {
private int price ; // subscription total price in euro-cent
private int length ; // length of subscription in months
// constructor :
public Subscription(int p, int n) {
price = p ;
length = n ;
}
/**
* Calculate the monthly subscription price in euro,
* rounded up to the nearest cent.
*/
public double pricePerMonth() {
double r = (double) price / (double) length /100.0;
return r ;
}
/**
* Call this to cancel/nulify this subscription.
*/
public void cancel() { length = 0 ; }
}
用JUnit测试:
SubscriptionTest.java:
package wintys.junit;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class SubscriptionTest {
Subscription S;
@Before
public void setUp() throws Exception {
S = new Subscription(200,2) ;
}
@After
public void tearDown() throws Exception {
S = null;
}
@Test
public void testPricePerMonth() {
assertEquals(S.pricePerMonth() , 1.0);
}
}
[参考资料]:
JUnitQuickTutorial : http://code.google.com/p/t2framework/wiki/JUnitQuickTutorial
分享到:
相关推荐
junit4.5所有的包都在里面~
JUnit4.5包和一些相关的文档,如API,是学习JUnit的必备资料。
单元测试工具,可以加载到eclipse!比较常用的测试工具!
JUnit4.5API参考手册 JUnit4.5API参考手册
使用javadocchm制作的junit4.5帮助文档,方便查询。
junit4.4+junit4.5+开源码打包下载
单元测试是开发者编写的一小段代码,用于检验被测代码的一个很小的、很明确的功能是否正确。通常而言,一个单元测试是用于判断某个特定条件下某个特定函数的行为。其实我们每天都在做单元测试。
用Junit进行单元测试
chm格式的junit API 文档,方便离线使用
单元测试是开发者编写的一小段代码,用于检验被测代码的一个很小的、很明确的功能是否正确。通常而言,一个单元测试是用于判断某个特定条件下某个特定函数的行为。其实我们每天都在做单元测试。
junit测试软件是一单元测试,集成测试工具
单元测试所需的junit jar包,里面包含class jar 和源码jar,JUnit 是JAVA语言事实上的标准测试库。JUnit 4是三年以来最具里程碑意义的一次发布。它的新特性主要是针对JAVA5中的标记(annotation)来简化测试,而不是...
junit-4.5-SNAPSHOT-20070720-
junit-4.5 junit-4.5 junit-4.5 junit-4.5 junit-4.5 junit-4.5
JUnit is a framework for implementing testing in Java. It provides a simple way to explicitly test specific areas of a Java program, it is extensible and can be employed to test a hierarchy of program...
前提:本文假设读者已经具有使用JUnit 4以前版本的经验。
junit tutorial e-book
本资源适合具有一定junit test 的开发者,介绍了mockito最常用的用法
JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage,包含依赖包:junit-jupiter-5.5.1.jar,junit-jupiter-engine-5.5.1.jar,junit-jupiter-params-5.5.1.jar,junit-platform-launcher-1.5.1.jar,junit-...
ALevin作为一个很好的虚拟网络仿真平台,它的开源给我们的学习带来很大方便,但在这之前我们先要将环境配置好,才能更好的使用着个开源工具,由于ALevin要求JUnit 4.5 或更高版本, 因此为了方便大家交流学习, 这里...