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

前端 未结 5 1165
误落风尘
误落风尘 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:48

    That looks about right to me. Yes, you will write a lot of Unit Tests and, initially, it will seem like overkill and TBH a waste of time; but stick with it, it'll be worth it. What you should be aiming for (rather than just 100% code coverage) is 100% function coverage. However... if you find that you're writing a lot of UTs for the same method it's possible that that method is doing too much. Try separating your concerns more. In my experience the body of an Action should be doing little more than newing-up a class to do the real work. It's that class that you should really be targeting with UTs.

    Chris

提交回复
热议问题