简体   繁体   中英

What we need to test in Observer design pattern unit testing?

I am new to software testing. I wonder what is the right way to make a unit testing for observer pattern? eg if we have the following 4 classes implemented:

  • Subject class(attach/detach/notify)
  • Observer interface class (update virtual method)
  • ConcreteSubject class
  • ConcreteObserver (concrete update method)

How to write test tracks for each of these classes? Is there any good example to take a reference?

This is a tough question to answer because it's pretty abstract. Typically you don't write tests for certain patterns, you write unit tests for methods. Or you write tests based on use cases. The bottom line is that when you provide input, what is the expected output? It doesn't matter what pattern is used; input goes in, result comes out. Was the result valid? That's your test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM