`
石建武
  • 浏览: 74142 次
  • 性别: Icon_minigender_1
  • 来自: 陕西
社区版块
存档分类
最新评论

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

阅读更多
一、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.csdn.net/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
分享到:
评论

相关推荐

    jUnit入门教程 jUnit教程

    学习时候从网络上整理的juint资料,非常基础.

    Java学习笔记-个人整理的

    \contentsline {chapter}{Contents}{2}{section*.1} {1}Java基础}{17}{chapter.1} {1.1}基本语法}{17}{section.1.1} {1.2}数字表达方式}{17}{section.1.2} {1.3}补码}{19}{section.1.3} {1.3.1}总结}{23}{...

    Java学习单元测试:有关使用Java学习单元测试的笔记

    用Java学习单元测试我的Java学习单元测试笔记新的优先级:(下面的修复)仍然需要更加自信地与项目一起设置JUnit 5测试...并使用版本控制/ git。 问题:IntelliJ无法识别木星-可能正在配置某些问题。 另一种方法是...

    Java开源例程ClockSimpleJEE4 0.97 安全增强和架构整理版

    Java开源例程ClockSimpleJEE4 0.97 安全增强和架构整理版 以下是readme和release note ClockSimpleJEE4是开源例程企业考勤系统 用于Java,mysql学习。 所有程序在GPLv3条款下开源,关于GPLv3相关pdf已放置在doc...

    jdk1.8-source-analysis:JDK1.8源码分析

    1.请手动添加jdk下面的lib到path中2.lib文件夹下面的junit测试jar包添加到路径中,刹车编写测试用例学习计划以下为小编整理的通常所需阅读的二进制范围。标题为包名,后面序号为优先级1-4,优先级递减1,java.lang 1...

    jdk1.8-source-analysis:Java 8源码分析,JUC,ThreadPool,Collection

    2.lib文件夹下面的junit测试jar包添加到路径中,刹车编写测试用例 学习计划 以下为小编整理的通常所需阅读的二进制范围。标题为包名,后面序号为优先级1-4,优先级递减 1,java.lang 1) Object 1 2) String 1 3) ...

    Test-Driven+Development+By+Example-测试驱动开发【高清+有目录+可搜索+可编辑】

    1.敏捷开发强调测试先行,因为先编写测试代码,就可以有目的的预防某些bug的产生,要知道,治病不如预防!!!所以我个人觉得这个还是比较重要的,文件也不大,只有8M,但是高清。 2.本版本与网上其他资源不同之处...

    java源码剖析-JavaSourceLearn:JDK1.8源码的代码分析和学习

    2.lib文件夹下面的junit测试jar包添加到path中,以便编写测试用例 学习计划 很多java开发的小伙伴都会阅读jdk源码,然而确不知道应该从哪读起。以下为小编整理的通常所需阅读的源码范围。 标题为包名,后面序号为...

    【白雪红叶】JAVA学习技术栈梳理思维导图.xmind

    关于java程序员发展需要学习的路线整理集合 技术 应用技术 计算机基础知识 cpu mem disk net 线程,进程 第三方库 poi Jsoup zxing Gson 数据结构 树 栈 链表 队列 图 操作系统 linux 代码控制...

    Collections源码java-jdk1.8-source-analysis:Java8源码分析,J.U.C、ThreadPool、Col

    2.lib文件夹下面的junit测试jar包添加到path中,以便编写测试用例 学习计划 很多java开发的小伙伴都会阅读jdk源码,然而确不知道应该从哪读起。以下为小编整理的通常所需阅读的源码范围。 标题为包名,后面序号为...

    jdk8-source-code:jdk源码解析

    1.请手动添加jdk下面的lib到path中2.lib文件夹下面的junit测试jar包添加到路径中,刹车编写测试用例学习计划以下为小编整理的通常所需阅读的二进制范围。标题为包名,后面序号为优先级1-4,优先级递减1,java.lang 1...

Global site tag (gtag.js) - Google Analytics