写作与QUOT;单元测试" code? [英] Writing "unit testable" code?
本文介绍了写作与QUOT;单元测试" code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你用什么样的做法,以使您的code的单元测试友好吗?
What kind of practices do you use to make your code more unit testing friendly?
推荐答案
-
TDD - 先写测试,力量
你想想可测试性和
帮助写code,实际上是
需要的,不是你认为你可能
需要
TDD -- write the tests first, forces you to think about testability and helps write the code that is actually needed, not what you think you may need
重构到接口 - 品牌
嘲讽容易Refactoring to interfaces -- makes mocking easier
公共虚拟方法
接口 - 使嘲弄更容易Public methods virtual if not using interfaces -- makes mocking easier
依赖注入 - 使得嘲讽
容易Dependency injection -- makes mocking easier
更小,更有针对性的方法 -
测试是更集中,更容易
写Smaller, more targeted methods -- tests are more focused, easier to write
静态类的规避
避免单身,除非
必要Avoid singletons, except where necessary
避免密封类
这篇关于写作与QUOT;单元测试" code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文