关于单测哪些事儿

writing-standards-for-unit-testing

Unit Test的三A原则: Arrange, Act, Assert

  • 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.

或者说5个原则

  • Unit tests have one assert per test.
  • Avoid if-statements in a unit test.
  • Unit tests only “new()” the unit under test.
  • Unit tests do not contain hard-coded values unless they have a specific meaning.
  • Unit tests are stateless.

不是Unit Test

  • It talks to the database
  • It communicates across the network
  • It touches the file system
  • It can’t run at the same time as any of your other unit tests
  • You have to do special things to your environment (such as editing config files) to run it.

Test Driven Development FAQ

微软的单测实践


八卦时间——

[Michael Feathers]是世界级面向对象技术专家,以丰富的软件项目开发经验著称。目前在世界顶尖的软件咨询公司从事敏捷方法/极限编程、测试驱动开发、重构、面向对象设计、Java、C#和C++等方面的培训和项目指导。他是著名测试框架CppUnit和FitCpp的开发者,已经主持了三次面向对象界盛会OOPSLA上的CodeFest比赛。他还是《修改代码的艺术》(Working Effectively with Legacy Code)一书的作者。

Michael Feathers is the founder and Director of R7K Research & Conveyance, a company specializing in software and organization design. Michael is also the author of the book Working Effectively with Legacy Code (Prentice Hall, 2004).

wiki Jim_Coplien在2014年发表了一篇:Most Unit Testing Is Waste (2014) [pdf] 然后一石激起千层浪:

然后Coplien大佬出了第二季

Uncle Bob and Jim Coplien’s debate on TDD提到更早之前(2008年2月),Cope大老讨论Coplien and Martin Debate TDD, CDD and Professionalism另外一位Uncle Bob

Bob Martin is an Agile Manifesto author, and author of books on Agile Programming, XP, UML, O-O Programming, and C++. He is CEO and president of Object Mentor www.objectmentor.com/ Jim Coplien is a software pioneer in o-o programming and C++ and multi-paradigm design. He appreciates the human side of design, and has written critically acclaimed books on design and development.

 
comments powered by Disqus