编写单元测试标准 [英] Writing standards for unit testing

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

问题描述

我计划在我的团队中引入一系列写单元测试的标准。但是要包括什么?



这两个帖子(单元测试命名最佳做法



我的标准中应该涵盖的其他域名应该包含在我的标准中。如何设置测试类以及如何组织它们。例如,如果有一个名为OrderLineProcessor的类,应该有一个名为OrderLineProcessorTest的测试类。如果在该类上有一个名为Process()的方法,那么应该有一个名为ProcessTest的测试(可能更多的测试不同的状态)。



/ p>

贵公司是否有单元测试的标准?



编辑:我使用的是Visual Studio Team System 2008我在C#.Net开发

解决方案

看看 Michael Feathers什么是单元测试(或什么使单元测试坏单元测试)



查看Arrange,Act,Assert的想法,即一个测试只以三个固定顺序执行:




  • 排列测试所需的任何输入数据和处理类

  • 执行测试 li>
  • 使用一个或多个断言测试结果。是的,它可以是多个断言,只要他们都努力测试所执行的操作。



查看行为驱动开发,以便将测试用例与需求对齐。



此外,我对今天的标准文档的看法是,你不应该写它们,除非你必须 - 有很多已经写的资源。链接到他们,而不是重新散播他们的内容。为想了解更多资讯的开发人员提供阅读清单。


I plan to introduce a set of standards for writing unit tests into my team. But what to include?

These two posts (Unit test naming best practices and Best practices for file system dependencies in unit/integration tests) have given me some food for thought already.

Other domains that should be covered in my standards should be how test classes are set up and how to organize them. For example if you have class called OrderLineProcessor there should be a test class called OrderLineProcessorTest. If there's a method called Process() on that class then there should be a test called ProcessTest (maybe more to test different states).

Any other things to include?

Does your company have standards for unit testing?

EDIT: I'm using Visual Studio Team System 2008 and I develop in C#.Net

解决方案

Have a look at Michael Feathers on what is a unit test (or what makes unit tests bad unit tests)

Have a look at the idea of "Arrange, Act, Assert", i.e. the idea that a test does only three things, in a fixed order:

  • Arrange any input data and processing classes needed for the test
  • Perform the action under test
  • Test the results with one or more asserts. Yes, it can be more than one assert, so long as they all work to test the action that was performed.

Have a Look at Behaviour Driven Development for a way to align test cases with requirements.

Also, my opinion of standard documents today is that you shouldn't write them unless you have to - there are lots of resources available already written. Link to them rather than rehashing their content. Provide a reading list for developers who want to know more.

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

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