---
title: "JUnit -- 分析"
author: "orange5458"
date: "2011-12-11T18:08:56Z"
tags: []
categories: ["开源软件"]
slug: "junit"
draft: false
lastmod: "2011-12-11T18:08:56Z"
id: 1305042
url: "https://orange5458.iteye.com/blog/1305042"
---

1.类结构图

 

![](http://dl.iteye.com/upload/attachment/603928/b22dd441-6228-3ffa-aaf8-a66f27c2efcb.jpg)

 

Assert ： 大量的assert开头的结果和预期判定方法，如果判定失败则抛出AssertionFailedError

TestCase ： 一个实例对应测试用例，对应fName名称对应的方法

TestResult ： 保存测试结果，

fFailures --&gt; AssertionFailedError集合

fErrors --&gt; 除AssertionFailedError，ThreadDeath之外的Throwable集合

fListeners --&gt; TestListener集合

TestSuite ： 一组TestCase实例的集合，

可以在构造时传入一个Class对象，自动为该类中每一个以test开头的无参void返回类型方法创建一个TestCase实例

TestRunner ： 客户对象调用的起点，负责对整个测试流程的跟踪。能够显示返回的测试结果，并且报告测试的进度。

不同的环境中有不同的TestRunner，如junit.textui.TestRunner，junit.awtui.TestRunner ......  
 

2.运行时序图

- TestRunner
- ![](http://dl.iteye.com/upload/attachment/604039/2107e3a5-ea74-35c7-8937-bb01e389c1be.jpg)
- TestSuite
- ![](http://dl.iteye.com/upload/attachment/604041/b8297ab2-c193-3af4-8285-87b6260cc698.jpg)
- TestCase
- ![](http://dl.iteye.com/upload/attachment/604043/9eb5101d-eef1-3174-9bf4-7138bb09d258.jpg)