且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET MVC - 单元测试矫枉过正? (TDD)

更新时间:2023-02-17 12:20:47

这一切都取决于你有多少报道需要/想和多少可靠性是一个问题。

It all depends on how much coverage you need / want and how much dependability is an issue.

这里有问题,你应该问自己:


  • 这是否单元测试有助于实现功能/ code修改,我还没有?

  • 请问这个单元测试帮助回归测试/调试这个单位,如果我做出改变以后呢?

  • 是code,以满足这个单元测试不平凡的或值得为它写单元测试?

  • Does this unit test help implement a feature / code change that I don't already have?
  • Will this unit test help regression test/debug this unit if I make changes later?
  • Is the code to satisfy this unit test non-trivial or does it deserve a unit test?

关于第三届之一,我记得当我开始写单元测试(我知道,不是一回事TDD)我会测试,会是这样:

Regarding the 3rd one, I remember when I started writing unit tests (I know, not the same thing as TDD) I would have tests that would go like:

string expected, actual;
TypeUnderTest target = new TypeUnderTest();
target.PropertyToTest = expected;
actual = target.PropertyToTest;
Assert.AreEqual<string>(expected, actual);

我可以做更多的东西生产力与我的时间就像选择一个更好的壁纸我的桌面。

I could have done something more productive with my time like choose a better wallpaper for my desktop.

我推荐这篇文章ASP.net MVC书作者桑德森:

I recommend this article by ASP.net MVC book author Sanderson:

http://blog.$c$cville.net/2009/08/24/writing-great-unit-tests-best-and-worst-practises/