What are the differences between xUnit, NUnit and MSTest?
Quick Answer
All three are mature .NET test frameworks. xUnit is the modern default for new projects — no [SetUp]/[TearDown] (constructor + IDisposable instead), one instance per test, [Fact]/[Theory]. NUnit is feature-rich with a fluent assertion model and lots of attributes. MSTest is Microsoft's, ships with Visual Studio, historically less flexible but now competitive.
They all do the same job. xUnit is what I'd pick for a new project — it drops the setup/teardown attributes in favour of the constructor and IDisposable, it creates a new instance of the test class for every test so isolation is automatic, and parameterised tests are [Theory] with [InlineData]. NUnit has more attributes and a fluent constraint-based assertion syntax, and it reuses one class instance. MSTest is Microsoft's and integrates tightly with Visual Studio. Honestly the difference is small — the important thing is consistency, and I'd add FluentAssertions on top of whichever one for readable assertions.
- xUnit: a fresh test class instance per test method (better isolation);
[Theory]+[InlineData]/[MemberData]for parameterised tests; setup in the constructor. - NUnit:
[SetUp],[TestCase],[Values], richAssert.That(...)constraint model, one class instance reused. - MSTest:
[TestInitialize],[DataRow], tight VS integration. - The choice rarely matters much — pick one and be consistent. Assertion libraries (FluentAssertions, Shouldly) are used with any of them.