Author : HASSAN MD TAREQ

xUnit.net

Installation

Install-Package xunit

Test project

  • Main Project: Foo
  • Test Project: Foo.Test
  • Right Click on Solution > Add > New Project > Test > xUnit Test Project > Foo.Test

Notes:

  • When using Test Template to create test project following dependency added automatically:
    • xunit (core + assert + analyzers)
    • xunit.runner.visualstudio
  • Adding test runner manually: Install-Package xunit.runner.visualstudio
  • Any package can be added seperately. See: What NuGet Packages Should I Use?

Add reference of MainProject to TestProject
Foo.Test > Right Click on Dependency > Add Reference > Check MainProject > Ok

Convention to follow

  • For every class in Main Project, there should be a test class with suffix Test (i.e. Bar.cs => BarTest.cs)
  • One test method per test case
  • Test method name should clearly explain the test case

Running Test

Menu > Test > Windows > Test Explorer