Unit Testing - amitbhilagude/userfullinks GitHub Wiki

  1. Overview
    1. Three Types
      1. MS Test
      2. NUnit
      3. xUnit
    2. All three test methods are good. They use different NuGet packages for Unit tests and Test adapters.
    3. Test Adapter is used for runtime test discovery. If you remove this package. No test will be shown in Test explorer.
  2. MS Test
    1. Class Attribute: [TestClass]
    2. Initialise Test cases Method: [TestInitialize]
    3. Each Test case method: [TestMethod]
  3. NUnit
    1. Class Attribute: [Test Fixture]
    2. Initialise Test cases Method: [SetUp]
    3. Each Test case method: [Test]
  4. xUnit
    1. Class Attribute: No decoration
    2. Initialise Test cases Method: Replaced with the constructor of a class
    3. Each Test case method: [Fact]
  5. Visual Studio Enterprise Version Features
    1. Code Coverage
      1. Gives detailed information about how much code coverage we have for each method.
    2. Live Unit Testing
      1. Gives you to test your code during development.
      2. You don't have to go to test explorer. you can start live testing by putting a breakpoint. it also gives an indication if this method is covered by test cases.
  6. Unit Testing for Static methods for NUnit where every test cases works in Isolation.
    1. Challenge with Static method if there is class A is calling Static class B then we can't test. If static class B is referring app setting for DB connections
    2. Better option is to use Dependency injection and use class B through DI only.
  7. Best practices
    1. Use NCrunch as a test runner. A good option is to run tests in the background and highlight the issue run time. https://www.ncrunch.net/