Short Note in terms of compare Unit Testing Frameworks in C#

DESCRIPTION NUNIT MSTEST XUNIT
Marks a test method/individual test [Test] [TestMethod] [Fact]
Indicates that a class has a group of unit tests [TestFixture] [TestClass] N.A
Contains the initialization code, which is triggered before every test case [SetUp] [TestInitialize] 👎 Constructor
Contains the cleanup code, which is triggered after every test case [TearDown] [TestCleanup] IDisposable.Dispose
Contains method that is triggered once before test cases start [OneTimeSetUp] [ClassInitialize] IClassFixture<T>
Contains method that is triggered once before test cases end [OneTimeTearDown] [ClassCleanup] IClassFixture<T>
🥱 Contains per-collection fixture setup and teardown N.A N.A ICollectionFixture<T>
Ignores a test case [Ignore("reason")] [Ignore] [Fact(Skip="reason")]
Categorize test cases or classes [Category()] [TestCategory("")] [Trait("Category", "")]
Identifies a method that needs to be called before executing any test in test class/test fixture [TestFixtureSetup] [ClassInitialize] 👎 N.A
Identifies a method that needs to be called after executing any test in test class/test fixture [TestFixtureTearDown] [ClassCleanUp] 👎 N.A
Identifies a method that needs to be called before the execution of any tests in Test Assembly N.A 😱 [AssemblyInitialize] N.A
Identifies a method that needs to be called after execution of tests in Test Assembly N.A 😱 [AssemblyCleanUp] N.A

Bold text is important note.

XUnit have shared Constructor for all test cases within a Test Class. Then it will be an issue if you have used shared property or Database.

Example, in constructor you have defined a List contains {1, 2, 3}

  • Then in First test case you add a number of item (by a random method) to the shared List, then the list will be {1 , 2,  3, <random items>} and you assert the list should be 3 + <number of random items> items (you assumption it will be true).
  • After that in the Second test case you just assert the list should be 3 (the initial list) and you assumption it will be true.
  • BUT the IDE will run Unit Test cases in parallel then sometime execute the second test case before first test case and vice versa (honestly you can define the Order of test case, but in normal use case we don't because we don't want to make or use a complex feature).
  • THEN the test cases result something fail or success 💩

💋 With Me, MSTEST is the BEST CHOICE.

More Detail

NUnit vs. XUnit vs. MSTest: Comparing Unit Testing Frameworks In C#
This blog compares the three major C# Unit testing frameworks: NUnit, xUnit, and MSTest, along with the demonstration using the Remote Selenium Grid.