Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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
add comment

4 Answers 4

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)

share|improve this answer
add comment

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

share|improve this answer
add comment

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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

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.