I am looking for good resources on how to write good unit test cases in C#/Dot Net. Books, resources on the net or simply good advises. In particular the unit cases should give good code coverage and cover all functionality.

4 Answers 4


Have you tried the book The Art of Unit Testing ? http://www.manning.com/osherove/


I highly recommend the book "Pragmatic Unit Testing in C# with NUnit" by Andrew Hunt and David Thomas.

If you are using Visual Studio as your IDE you might also want to check out MSDN (e.g. http://msdn.microsoft.com/en-us/library/ms182532.aspx)


General Rules:

  • At least one test method should be written for every public service method and every new or overridden repository method
  • Where applicable, positive and negative tests should be written
  • Every Assert should include a relevant, meaningful error message for when failure occurs
  • The Arrange, Act, Assert pattern should always be followed (see below)
  • Read this article on MSDN: Guidelines forTest-Driven Development.

Arrange, Act, Assert:

Follow the "3-As" pattern for test methods: (Arrange, Act, Assert). Specifically, use separate code paragraphs (groups of lines of code separated by a blank line) for each of the As.

  • Arrange is variable declaration and initialization.
  • Act is invoking the code under test.
  • Assert is using the Assert.* methods to verify that expectations were met. Following this pattern consistently makes it easy to revisit test code.

This makes it much easier to see:

  • What is being set up and initialized in the arrange section
  • What method is being executed in the act section
  • What determines the outcome of the test in the assert section

See the following post for more details http://tekprolixity.blogspot.com/2012/04/unit-testing-guidelines.html


I would suggest look into this MSDN link. But you can bing "unit test using VSTS" and you will get tons of help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.