73

I wondered which unit testing framework would be a good one to get really familiar with? I know this might be a question of opinion, but I thought I'd ask anyways. I know that I will need to do it someday, so I might as well learn to use it. I know that there is quite a few out there, but which one is effective for C# development?

From this question I can see that unit testing is necessary, but personally I haven't used it. So that's why I ask this question.

Community
  • 1
  • 1
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
  • This really is a bad question and should be closed as S&A. Neither does it contain any good answers besides "hey I use xyz and it's really cool" nor is it a valuable resource for anyone searching for a comparison of the current frameworks. – Johannes Rudolph May 07 '10 at 06:35
  • http://stackoverflow.com/questions/261139/nunit-vs-mbunit-vs-mstest-vs-xunit-net – nawfal Jul 23 '14 at 15:16
  • 2
    I find this is one of the main issues with people I talk with about this site. You have these strict rules about asking questions that are bombed by question trolls, people just want to be able to ask an honest question and get a good answer. If you're going to curate each question maybe curate the bad answers instead and let people learn from this sites community holistically they way they want. this cant be the first time and the amount of times that people ask questions on here cant be that small. So work a better way to address this then banning people from asking questions for 6 months. – Rob May 20 '17 at 00:47

7 Answers7

57

Personally, I prefer the Visual Studio Unit Testing Framework, for two main reasons:

  • It integrates seamlessly with the IDE;
  • It's one less program to deploy in a dev environment.

Having said that, pretty much any unit testing framework will do the trick, the important thing is to have tests!

Aaronaught
  • 120,909
  • 25
  • 266
  • 342
  • 13
    the downside of that is: your TFS needs a VS license too, if you want (you do!) continiuous integration build running the tests. That may be no problem for bigger shops or partners but at least it is one more thing to take into account. – mbx Oct 22 '14 at 16:19
  • 5
    NUnit now supports integrating seamlessly with the IDE and doesn't need any deployment (if using NuGet). – John Gietzen Aug 25 '15 at 14:27
  • 1
    @mbx - No VS license is required for TFS build agents. – Spivonious Nov 13 '15 at 15:09
  • 2
    @Spivonious Technically the TFS/Build agent needs a licensed VS. However: _If you have one or more licensed users of Visual Studio Enterprise with MSDN, or Visual Studio Professional with MSDN, then you may also install the Visual Studio software as part of Team Foundation Server 2015 Build Services. This way, you do not need to purchase a Visual Studio license to cover the running of Visual Studio on the build server for each person whose actions initiate a build._ see: [VS and MSDN Licensing Whitepaper](https://www.microsoft.com/en-us/download/details.aspx?id=13350) – mbx Nov 14 '15 at 18:03
41

I would go with NUnit.

Some links: NUnit QuickStart, NuGet Package

Sjoerd222888
  • 3,228
  • 3
  • 31
  • 64
Adriaan Stander
  • 162,879
  • 31
  • 289
  • 284
  • 3
    ReSharper gives NUnit seamless IDE integration (plus many more benefits). – TrueWill Feb 14 '10 at 20:47
  • I've heard (haven't tried yet) that today, MSTest has improved significantly - and doesn't really lack behind NUnit or others. Is that true? Or would you still recommend using NUnit for new projects even today? – Yoav Feuerstein Apr 28 '19 at 12:43
35

Don't get stuck on choosing a framework. Just pick one and start testing - they're not all that different. When you have written tests for a while, you will know what to look for, to suit your needs.

Personally, I have found xUnit, Testdriven.Net and Moq to be a very flexible set of test tools.

Also see this post: NUnit vs. MbUnit vs. MSTest vs. xUnit.net

Community
  • 1
  • 1
Luhmann
  • 3,860
  • 26
  • 33
6

I've decided to stick with NUnit because ReSharper provides native IDE support (which saves a lot of time). It's also supported by TeamCity in running and reporting automated tests.

mythz
  • 141,670
  • 29
  • 246
  • 390
2

I use NUnit for the testing framework and ReSharper for integrating it into VS (and everything else ReSharper does).

Robert Rossney
  • 94,622
  • 24
  • 146
  • 218
1

Use MbUnit (with Gallio), NUnit, MsTest or xUnit. You can combine several unit tests. I use NUnit for TDD

maxname
  • 5
  • 4
0

There are a few reasons for testing, thus a few testing environments. Plus, there are levels of testing, like simple, stubs, and mocks. For example, you could test behavior rather than state.

As far as function, I usually use the Visual Studio built in setup, add a reference to the NUnit dll, and change the c# annotations to be NUnit. This is because I like testing outside of Visual Studio, especially when it involves others on my team (and we didn't buy the team edition of VS yet).

Zachary Scott
  • 20,968
  • 35
  • 123
  • 205