NET Core 2: Why xUnit and not NUnit or MSTest
Tags: unittest, testframework, softwaredevelopment, testing
Published: 2018-03-13 02:08:55


---
title: NET Core 2: Why xUnit and not NUnit or MSTest
published: true
description: Brief post about why my team choose xUnit for our new project
tags: unit-test, test-framework,software-development, testing
cover_image: https://thepracticaldev.s3.amazonaws.com/i/xlhdyocetu2glko71j8t.png
---


With a recent new project using NET Core 2, my team and I looked at whether we should move to MS Test(Didn't consider MS Test 2 at that time), stick with NUnit or try xUnit. We had a spike, where I looked into whether we could still use NUnit in case we were not able to use xUnit, as we were not keen on MSTest as an alternative framework. In the end, we decided to give xUnit a go!

xUnit is pretty lean compared to NUnit and MsTest and has been written more recently. The .NET framework has evolved since NUnit was first created. XUnit leverage some of the new features to help developers write cleaner test, as tests should be kept clean and treated as first-class citizens. The authors wanted to codify some rules rather than repeating guidance about “do X” or “don’t do Y". You can read more about why xUnit was created here:  [https://xunit.github.io/docs/why-did-we-build-xunit-1.0.html](https://xunit.github.io/docs/why-did-we-build-xunit-1.0.html).


**Some of the reasons why we went with xUnit:**

-   NUnit was not fully compatible with .NET Core 2 at the time
-   We wanted to move away from MS Test, as the team preferred the xUnit and NUnit way of writing tests
-   xUnit is aimed at improving test isolation and trying to codify a set of rules to establish a testing standard.
-   xUnit \[Fact\] and \[Theory\] attributes are extensible, so you can implement your own testing functionality.xUnit doesn’t use Test Lists and .vsmdi files to keep track of your tests.
-   Microsoft is using xUnit internally, one of its creators is from Microsoft. xUnit was also created by one of the original authors of NUnit.
-   There are no \[Setup\] and \[Teardown\] attributes, this is done using the test class’ constructor and an IDisposable. This encourages developers to write cleaner tests.
-   xUnit allows us to write less code since its flexibility allows things like subspec which allow you to write only what you need to do. Using tools such as xBehave: [http://xbehave.github.io/]([http://xbehave.github.io/](https://reed.jiveon.com/external-link.jspa?url=http%3A%2F%2Fxbehave.github.io%2F).) and [Xunit.Gherkin.Quick](https://github.com/ttutisani/Xunit.Gherkin.Quick).
-   xUnit is easier to read and uses intuitive terminology.


An interesting recent article from Uncle Bob on (unit) testing:
[http://blog.cleancoder.com/uncle-bob/2017/05/05/TestDefinitions.html](http://blog.cleancoder.com/uncle-bob/2017/05/05/TestDefinitions.html)


A performance (with a new update to Visual Studio 2017) comparison was released a few months after picking our testing framework, comparing NUnit, xUnit and MS Test 2. You can find the blog post from Microsoft [here](https://blogs.msdn.microsoft.com/visualstudio/2017/11/16/test-experience-improvements/).


**References:**

[http://georgemauer.net/2015/05/01/why-not-mstest](http://georgemauer.net/2015/05/01/why-not-mstest)
[https://seankilleen.com/2015/06/xUnit-vs-MSTest/](https://seankilleen.com/2015/06/xUnit-vs-MSTest/)
[https://stackify.com/unit-test-frameworks-csharp/](https://stackify.com/unit-test-frameworks-csharp/)
[https://xunit.github.io/docs/why-did-we-build-xunit-1.0.html](https://xunit.github.io/docs/why-did-we-build-xunit-1.0.html)[http://blog.cleancoder.com/uncle-bob/2017/05/05/TestDefinitions.html](http://blog.cleancoder.com/uncle-bob/2017/05/05/TestDefinitions.html)