Jan 20, 2009

Unit Test Best practices

  • Arrange test in your solution

    It is common pratice to have a test class per tested class, a test rpoject per tested project and at lest one test method per tested method.

  • Naming tests: [MethodUnderTest]_[Scenario]_[ExpectedBehavior]
  • Use [Setup] and [TearDown] attributes to reuse code in your tests such as creating and initializing common objects all your tests use.
  • Don’t use [Setup] and [TearDown] to initialize or destroy objects which are not shared throughout the test class in all the tests, as it makes the tests less understandable (the reader won’t know which tests use the setup method and which don’t).

No comments:

Post a Comment