2.5 Observing results with TestListener(Design patterns in action: Observer)
利用此设计模式,在对象之间 ,我们可以定义一种"一对多"的依赖,那样当一个对象的state发生变化时,依赖于此的对象都得到通知并相应地自动更新.在JUnit里,把TestRunner作为一个TestListener注册到TestResult上的.(The TestRunner registering as a TestListener with the TestResult is an example of the Observer pattern.)
基于上面所说的设计模式,我们就可以很容易理解这段话了:"But does an object have to be a TestRunner to report on a test?Can more than one object report on a test at once?"JUnit框架中提供了TestListener,我们可以这个接口来access TestResult,并做出适合自己项目的测试报告.
you would only need to implement it if you were extending the JUnit framework, rather than just using it.
2.6 Working with TestCase
TestRunner(shipped with the framework) +TestSuite(provided automatically by JUnit,defaultly)+ TestCase = TestResult
这样为了得到TestResult,我们就可以只写TestCase了,通常一个TestCase包含有下面的两种主要的components: fixture和unit tests.
2.6.1 Managing resources with a fixture
利用此设计模式,在对象之间 ,我们可以定义一种"一对多"的依赖,那样当一个对象的state发生变化时,依赖于此的对象都得到通知并相应地自动更新.在JUnit里,把TestRunner作为一个TestListener注册到TestResult上的.(The TestRunner registering as a TestListener with the TestResult is an example of the Observer pattern.)
基于上面所说的设计模式,我们就可以很容易理解这段话了:"But does an object have to be a TestRunner to report on a test?Can more than one object report on a test at once?"JUnit框架中提供了TestListener,我们可以这个接口来access TestResult,并做出适合自己项目的测试报告.
you would only need to implement it if you were extending the JUnit framework, rather than just using it.
2.6 Working with TestCase
TestRunner(shipped with the framework) +TestSuite(provided automatically by JUnit,defaultly)+ TestCase = TestResult
这样为了得到TestResult,我们就可以只写TestCase了,通常一个TestCase包含有下面的两种主要的components: fixture和unit tests.
2.6.1 Managing resources with a fixture
本文介绍了如何使用JUnit框架结合观察者设计模式实现测试结果的通知机制。通过将TestRunner注册为TestListener,可以方便地获取TestResult,并根据项目需求定制测试报告。
181

被折叠的 条评论
为什么被折叠?



