unit testing for observer pattern

∥☆過路亽.° 提交于 2019-12-13 01:57:10

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4713757/unit-testing-for-observer-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!