简体   繁体   English

在观察者设计模式单元测试中我们需要测试什么?

[英]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:例如,如果我们实现了以下 4 个类:

  • Subject class(attach/detach/notify)主题类(附加/分离/通知)
  • Observer interface class (update virtual method)观察者接口类(更新虚方法)
  • ConcreteSubject class具体主题类
  • ConcreteObserver (concrete update method) ConcreteObserver(具体更新方法)

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.那是你的考验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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