测试工作(1 -- Junit3学习整理)

[size=small]一、Junit3

1.基础知识:

Junit3 :大量采用的java 反射机制实现,测试方法名必须是固定的格式。不能含有参数和返回值。
A.测试类 ----- (继承)TestCase ----- (继承)Assert
B.测试方法名固定:必须以 Test ** 开始,且函数无参数。
C. setUp 和 tearDown 在每次Test方法执行前后都会执行的初始化和销毁方法。
D.设计模式的体现


2.junit3的执行路径
http://www.ibm.com/developerworks/cn/java/j-lo-junit-src/ (推荐)
很深入的分析整个的junit的执行流程,并且自己可以结合文章的说明,debug执行,对junit的认识更加清楚。推荐阅读。
参考:1、http://dennis-zane.iteye.com/blog/68660
2、http://blog.youkuaiyun.com/ai92/archive/2005/03/12/318318.aspx


3.涉及的主要类
abstract class TestCase extends Assert implements Test
* A test case defines the fixture to run multiple tests. To define a test case<br>
* 1) implement a subclass of TestCase<br>
* 2) define instance variables that store the state of the fixture<br>
* 3) initialize the fixture state by overriding <code>setUp</code><br>
* 4) clean-up after a test by overriding <code>tearDown</code>.<br>
TestSuite implements Test
* A <code>TestSuite</code> is a <code>Composite</code> of Tests.
* It runs a collection of test cases. Here is an example using
* the dynamic test definition.
class TestResult extends Object
* A <code>TestResult</code> collects the results of executing
* a test case. It is an instance of the Collecting Parameter pattern.
* The test framework distinguishes between <i>failures</i> and <i>errors</i>.
* A failure is anticipated and checked for with assertions. Errors are
* unanticipated problems like an <code>ArrayIndexOutOfBoundsException</code>.
TestRunner extends BaseTestRunner
* A command line based tool to run tests.
abstract class BaseTestRunner implements TestListener
* Base class for all test runners.
class Assert
* A set of assert methods. Messages are only displayed when an assert fails.


补充知识:断言 assert
编写代码时,我们总是会做出一些假设,断言就是用于在代码中捕捉这些假设
可以将断言看作是异常处理的一种高级形式
断言表示为布尔表达式,程序员相信在程序中的某个特定点该表达式值为“真”。
单元测试必须使用断言(Junit/JunitX)。
The assertion statement has two forms. The first, simpler form is:
assert Expression1 ;
where Expression1 is a boolean expression. When the system runs the assertion, it evaluates Expression1 and if it is false throws an AssertionError with no detail message.
The second form of the assertion statement is:
assert Expression1 : Expression2 ;
where:
• Expression1 is a boolean expression.
• Expression2 is an expression that has a value. (It cannot be an invocation of a method that is declared void.)
Use this version of the assert statement to provide a detail message for the AssertionError. The system passes the value of Expression2 to the appropriate AssertionError constructor, which uses the string representation of the value as the error's detail message.

断言是jdk1.4之后引入的特性,默认为关闭,开启断言执行 : java –ea ClassName 。

参考:http://www.blogjava.net/liulu/archive/2006/10/24/77005.html[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值