Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

Have you tried the book The Art of Unit Testing ?

share|improve this answer

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.

share|improve this answer

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

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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