71

My company is upgrading our Visual Studio 2012 to 2013 Premium. In the midst of this, we are also looking to start automating our tests using Visual Studio Team Services

I have read a couple of MSTest vs nUnit posts and articles in the past but most of it compares the older version of MSTest. Also, nUnit had a lot of favourable reviews as compared to MSTest.

My question is, considering Microsoft's commitment towards the ALM, Agile practices and all the new stuff they've added into VS2013 Premium and Visual Studio Team Services to facilitate and encourage automated testing, how does MSTest compare to nUnit?

What other considerations should I take before making a decision on a testing framework to use?

Null Reference
  • 11,260
  • 40
  • 107
  • 184
  • Both MSTest and NUnit are stable for years (with no significant advancement), so I see no real need for another comparison if you can find old posts. – Lex Li Mar 26 '14 at 05:41

2 Answers2

59

MSTest hasn't changed much since it was originally introduced, so those old comparison posts are still valid. Microsoft's focus on ALM is mostly targeted at further tooling and server products, but the fundamental testing framework hasn't changed much.

It's also worth noticing that MSTest and their entire ALM strategy is targeted at many different styles of automated testing, including Integration Testing, System Testing, Performance Testing, etc., so while it attempts to be a one-size-fits-all, it's quite ill-suited for unit testing, because it's too heavy to work with.

While NUnit is better, I wouldn't recommend it either. It, too, hasn't changed much for years, and the extensibility model is frankly a mess.

Instead, I'd recommend xUnit.net. Although it's not perfect either, it's currently the best mainstream alternative on .NET. There are many reasons why xUnit.net is better than MSTest.

dodgy_coder
  • 12,407
  • 10
  • 54
  • 67
Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
  • 6
    is xUnit supported by TFS's continuous integration feature?' – Null Reference Mar 26 '14 at 07:33
  • You probably have to fiddle a bit with it, but it does have an MSBuild runner, bundled in http://www.nuget.org/packages/xunit.runners – Mark Seemann Mar 26 '14 at 07:41
  • @IsaacKleinman have you seen http://xunit.github.io/ ? ... it has a getting started tutorial and FAQs, not too bad. – dodgy_coder Oct 23 '14 at 00:59
  • I have, and I did choose xunit, but, unfortunately, unit testing have been my highest priority lately.. – Isaac Kleinman Oct 23 '14 at 01:02
  • Is this still the case in mid 2018 ? – Maverick Meerkat May 03 '18 at 09:19
  • 1
    @DavidRefaeli I haven't looked at MSTest since then, but I haven't heard anything about things having changed. I think it's telling that both the Roslyn, the .NET Core, and the ASP.NET Core code bases all use xUnit.net (and thereby *not* MSTest) as the unit testing framework. – Mark Seemann May 03 '18 at 09:32
  • MSTest is rewritten since Visual Studio 2017. It’s now called [MSTest v2](https://github.com/Microsoft/testfx). Several things has changed: it now supports both assertion for throwing exceptions, and parameterized test. – Franklin Yu Jul 17 '19 at 19:49
39

MSTest Vs NUnit:

  1. MSTest is integrated with VS so it'll be easy to use. NUnit will require third-party tools (some are free, some are paid).
  2. VS will give you Code Coverage in MSTest. NUnit requires DotCover (which is a paid tool).
  3. MSTest has an option to execute your tests in parallel if they don't depend on each other. This isn't a feature that NUnit provides.
  4. NUNit has TestCaseSourceAttribute which helps you to achieve parametrized test cases but in MSTest you'll need DataSourceAttribute which would be in XML file and will be difficult to manage when you have complex logic in the method.
  5. NUnit is faster as compared to MSTest.

Overall both frameworks are good to use, but I'd suggest going for NUnit.

Hp_issei
  • 579
  • 6
  • 18
arpitbakshi
  • 646
  • 4
  • 10
  • 1
    2: For NUnit you have free / open source OpenCover + ReportGenerator tools. – nzeemin Mar 23 '15 at 14:06
  • 8
    If you use ReSharper with Visual Studio, it will enable parallelization of NUnit tests. It also gives the integration that you mention in bullet #1. Not everyone has ReSharper, of course, but if you do, it takes away a couple of the advantages that MSTest have. – jfren484 Jun 29 '15 at 20:25
  • 3
    NUnit integrates with VS 2012's GUI Test runner. – Scott Marcus Feb 07 '16 at 19:59