I am new to 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
- 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.