观察者模式的单位测试 [英] unit testing for observer pattern
问题描述
如何为每个类编写测试轨?有没有一个很好的例子来参考?
感谢任何输入。
对于主题,您可以测试:
如果观察者很好附加(计数观察者的数量,并检查一个附加是否是好的),
和之后如果观察者
您还可以通过添加多个观察者进行检查,以确保您的观察者集合得到很好的实施。
您可以通过创建一个包含布尔值的模拟器观察器来检查通知,如果他被更新,则设置为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屋!