Click here to Skip to main content
15,879,326 members
Articles / DevOps / Unit Testing

Moving to xUnit.net

Rate me:
Please Sign up or sign in to vote.
4.20/5 (8 votes)
22 Jul 2015CPOL3 min read 13.5K   3   3
Moving to xUnit.net

xUnit.net is a free, open source, community-focused unit testing tool for the .NET Framework. Written by the original inventor of NUnit v2, xUnit.net is the latest technology for unit testing C#, F#, VB.NET and other .NET languages. xUnit.net works with ReSharper, CodeRush, TestDriven.NET and Xamarin.”

Many Test Framework are available in .NET: Microsoft Test, NUnit, xUnit, … Testing is an important aspect in Agile and XP and you can’t reach Continuous Deployment without it. Today, we write more and more tests, sometimes we have more tests than production code; that’s why a decent test framework is so important today.

Why Another Test Framework?

There are several articles & posts on the internet explaining the pros and cons of each Test Framework. Here are my –unordered- personal reasons:

Nuget ‘All the way’

You don’t need to install a vsix extensions to VS, or manually add a reference to a file-based dependency (Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll…. v10.0 or v10.1?) or to create a specific Test Project. In xUnit, you just need a basic class Library with a reference to the official Nuget. The VS Test Runner is even a nuget. Everything is distributed via nupkg and it’s terribly simple and efficient.

Great Community & Active Development

xUnit.net is free and open source. The code is hosted on github (800 commits, 30 contibutors) and was previously on codeplex. The core team is made of inspired evangelists and very active. The official twitter account has 1400 followers and it’s still growing. xUnit is extensible and a lot of extensions like AutoFixture are already available on nuget.org.

Part of the Next Big Thing

Do you know ASP.NET 5, Xamarin, DNX, …? xUnit is already compatible with all of these platforms. xUnit may be the first class citizen and default choice in .NET in the future. It’s not useless to spend a couple of hours to understand it.

xunitplatforms

Well Integrated in the .NET Ecosystem

There are troubles to switch to xUnit because it is already well integrated in the .NET ecosystem: Team Foundation Server, CruiseControl.net, AppVeyor, TeamCity, Resharper, TestDriven.net, …

It Helps to Write “Better, Faster, Stronger” Tests

It’s maybe the most important reason. I have the impression that parameterized tests (Via Theories), Generic Tests, extensibility via Attributes, Shared Context, … remove a lot of glue and frictions in my test project. Assertions & Attributes are quite common compared to the other test Frameworks but there are a few additional interesting properties.

xunittest

Integrating xUnit with Team Foundation Server

As I said, xUnit.net is already well integrated with several Build Server like AppVeyor or TeamCity. Using it with TFS is not so complicated, but we will have a few extra configuration steps.

xunitdlls

  1. Download the latest stable version of runner.visualstudio.
  2. Change the extension to zip and extract all the files.
  3. 3 assemblies should be in the folder build\_common
  4. The 3 files show to committed somewhere in TFS (up to you):
  5. Open Team Explorer Tab, Build -> Actions ->Manage Build Controllers, Select Properties. You should fill the TFS path to custom assemblies (xUnit):

controllersettings

That’s all. You can now write your tests and build your solution on the build agent. xUnit will be automatically used.

One particular problem in the current version is that TestFilters/TestCategories are not supported. xUnit has Traits but these ones are not understood by the runner. It’s common to mix unit tests & integration tests in a solution in order to have a better and stronger test strategy.

ctegories

If you are in this case, you have only two options:

  • Wait for xunit.runner.visualstudio 2.1 (summer 2015?)
    A recent commit added support to Test Filters. It’s a question a week to see it on prod. (Note: The fix is available on the public MyGet feed)
  • Create another solution without integration tests
    A little bit painful to maintain, but having a clean and fast solution to build is a good practice.

I’m completely convinced by xUnit.net and I hope you are too! If you still don’t know it, please give it a try.


Image 6 Image 7

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
France France
Yet another proof of concept

Comments and Discussions

 
QuestionSample project Pin
fredatcodeproject7-Aug-15 1:37
professionalfredatcodeproject7-Aug-15 1:37 
AnswerRe: Sample project Pin
Cybermaxs9-Sep-15 1:22
Cybermaxs9-Sep-15 1:22 
GeneralRe: Sample project Pin
fredatcodeproject9-Sep-15 5:28
professionalfredatcodeproject9-Sep-15 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.