单元测试接口 [英] Unit Testing Interfaces

查看:100
本文介绍了单元测试接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要测试接口?为什么不只测试该接口的具体对象呢?

Why test an interface? Why not just test the concrete object(s) of that interface?

推荐答案

IMO,因为接口不包含任何代码,所以您不应该浪费时间为它们编写测试(有什么要测试的?),如果您正在谈论C#中的接口.测试实现该接口的类,然后就可以进行操作.
IMO since interfaces do not contain any code, you should not waste time writing tests for them (what is there to test?), if you are talking about interfaces in C#. Test the classes that implement the interface and let it go at that.


创建模拟对象并不一定意味着要测试该接口-模拟对象本质上是充当代理"表示在测试期间可能不可用的另一个对象.
Creating a mock object does not necessarily mean that the interface will be tested - a mock object is essentially ''acting as a proxy'' for another object that may not be available during testing.


这篇关于单元测试接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆