问题描述
我计划在我的团队中引入一系列写单元测试的标准。但是要包括什么?
这两个帖子(和(或什么使单元测试坏单元测试)
查看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.
这篇关于编写单元测试标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!