ASP.NET MVC - Unit testing overkill? (TDD)

前端 未结 5 1166
误落风尘
误落风尘 2021-02-04 05:08

So I\'m starting to catch the TDD bug but I\'m wondering if I\'m really doing it right... I seem to be writing A LOT of tests.

The more tests the better

5条回答
  •  北恋
    北恋 (楼主)
    2021-02-04 05:33

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

    Here are the questions you should ask yourself:

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

    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(expected, actual);
    

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

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

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

提交回复
热议问题