观察者模式的单位测试 [英] unit testing for observer pattern

查看:242
本文介绍了观察者模式的单位测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相当新的软件测试。我想知道为观察者模式进行单元测试的正确方法是什么?例如如果我们实现了以下4个类:主题类(attach / detach / notify),Observer接口类(update virtual method),ConcreteSubject类和ConcreteObserver(具体更新方法)。
如何为每个类编写测试轨?有没有一个很好的例子来参考?



感谢任何输入。

解决方案

对于主题,您可以测试:
如果观察者很好附加(计数观察者的数量,并检查一个附加是否是好的),
和之后如果观察者



您还可以通过添加多个观察者进行检查,以确保您的观察者集合得到很好的实施。



您可以通过创建一个包含布尔值的模拟器观察器来检查通知,如果他被更新,则设置为true。



我找到一个链接,我不确定它可以作为参考,但我喜欢它,它可能会帮助你:



http://noticeablydifferent.com/UnitTesting/GOF/Observer.aspx


I am rather new for software testing. I wonder what is the right way to make a unit testing for observer pattern? e.g. if we have the following 4 classes implemented: Subject class(attach/detach/notify), Observer interface class (update virtual method), ConcreteSubject class, and ConcreteObserver (concrete update method). how to write test tracks for each of these classes? Is there any good example to take a reference?

Thanks for any inputs.

解决方案

For the Subject, you can test: if the observer is well attach(count the number of observers and check if the one attach is the good one), and after if the observer is well detach.

You can also check by adding more than one observer just to be sure your collection of Observers is well implemented.

You can check the notification by creating a mock observer that contains a boolean set to true if he is updated.

I find a link, I am not sure it could be use as reference but I like it, it might help you:

http://noticeablydifferent.com/UnitTesting/GOF/Observer.aspx

这篇关于观察者模式的单位测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆