63

I am getting back into a bit more .NET after a few-years of not using it full-time and am wondering what the good unit testing packages are these days.

I'm familiar with NUnit (a few years ago) and have played briefly around with IronRuby, with the goal of getting something like RSpec going, but I don't know much beyond that.

I realize I could google for this and call it a day, but I believe I'm likely to get a better and more informed response from asking a question here :-)

Suggestions?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Orion Edwards
  • 121,657
  • 64
  • 239
  • 328

11 Answers11

55

There are so many it's crazy. Crazy good, I guess.

  • For the conservative types (me), NUnit is still available and still more than capable.
  • For the Microsoft-types, MSTest is adequate, but it is slow and clunky compared to NUnit. It also lacks code coverage without paying the big bucks for the pricey versions of Visual Studio.
  • There's also MbUnit. It's like NUnit, but it has nifty features like RowTest (run the same test with different parameters) and Rollback (put the database back like you found it after a test).
  • And finally, xUnit.net is the trendy option with some attitude.
  • Oh, and TestDriven.NET will give you IDE integration for both NUnit and MbUnit.

I'm sure they're all just fine. I'd steer away from MSTest though, unless you just enjoy the convenience of having everything in one IDE out of the box.

Scott Hanselman has a podcast on this very topic.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brad Tutterow
  • 7,487
  • 3
  • 33
  • 33
  • 5
    +1, note NUnit 2.5 has the nice RowTest features, plus Combinatorial testing of arguments, etc. – user7116 Oct 15 '08 at 14:40
  • The difference between MSTest and NUnit are not that big if you ask me. It mostly boils down to preferred syntax and if you use TesteDriven.Net, which also supports MSTest, the performance is pretty much the same. – Kjetil Klaussen Feb 05 '09 at 12:06
  • Aye, NUnit 2.5 has RowTest features via the [TestCase] attribute. – Richard Szalay Jul 19 '09 at 20:37
8

Stick to NUnit. Don't go anywhere near MSTest.

NUnit + ReSharper is an absolute joy to work with.

Iain Holder
  • 14,172
  • 10
  • 66
  • 86
  • 1
    Why should you stear away from MSTest? I'd appreciate if you'd actually bothered to share WHY you wanna stear away from it. And R# works with MSTest as well (with the Gallio plugin). – Kjetil Klaussen Feb 05 '09 at 12:07
  • 1
    Hi Kjetil. It's mainly for three reasons. 1. The meta-data that the MS tests create. Why? Reflect like NUnit. 2. The test runner is horrid. 3. NUnit does everything better - why change. I did for a while but then changed back. – Iain Holder Feb 05 '09 at 12:24
  • I've also encountered various bugs with the MS test "runner". Basically VS leaves it running in the background and under certain circumstances tests you ran 10 minutes ago can interfere with the one you're about to run right now :-( – Orion Edwards Mar 17 '09 at 19:43
  • 1
    Note: Since around VS2017/dotnetcore, microsoft have rewritten all the MSTest stuff. There's now an MSTestV2 and the runner/model are very much the same as what you'd expect from NUnit and other such things, so I think MSTest is a much more viable option these days – Orion Edwards Jan 08 '19 at 20:28
  • Interesting, I’ll check it out. My answer is over a decade old now so is probably less accurate than it once was. :-) – Iain Holder Jan 09 '19 at 14:37
8

We use NUnit and MbUnit here. We use TestDriven.NET to run the unit tests from within Visual Studio. We use the excellent, highly recommended RhinoMocks as a mock framework.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
6

xUnit.net looks like it provides a slightly different approach to NUnit, MbUnit, and MSTest, which is interesting.

In my search for an RSpec-like solution (because I love the RSpec), I also came across NSpec, which looks a bit wordy, but combined with the NSpec Extensions addon to use C# 3 extension methods, it looks pretty nice.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Orion Edwards
  • 121,657
  • 64
  • 239
  • 328
  • You may want to look at this NSpec (http://nspec.org). It's almost identical to RSpec. – Amir Aug 13 '12 at 19:52
6

I used to use NUnit, but now tend to use MbUnit, for two key features: 1. The RowTest feature allows you to easily run the same test on different sets of parameters, which is important if you really want thorough coverage. 2. The Rollback feature allows you to run tests against your database while rolling back changes after every test, keeping your database in exactly the same state every time. And it's as easy as adding the [Rollback] attribute.

Another nice aspect of MbUnit is that its syntax is nearly identical to NUnit, so if you have a whole test bed already in place under NUnit, you can just switch out the references without the need to change any (very much?) code.

Doug R
  • 5,749
  • 2
  • 28
  • 32
5

I use the following:

TestDriven.NET - Unit testing add on for Visual Studio

Typemock Isolator- Mocking framework for .NET unit testing

NUnit - An open source unit testing framework that is in C#.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
4

You might find it interesting that Gallio v3.1 now supports RSpec via IronRuby.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jeff Brown
  • 1,178
  • 5
  • 8
3

I like TestDriven.NET (even though I use ReSharper) and I'm pretty happy with XUnit.net. It uses Facts instead of Tests which many people dislike but I like the difference in terminology. It's useful to think of a collection of automatically provable Facts about your software and see which ones you violate when you make a change.

Be aware that Visual Studio 2008 Professional (and above) now comes with integrated Unit Testing (it used to be available only with the Team System Editions) and may be suitable for your needs.

Mike Minutillo
  • 54,079
  • 14
  • 47
  • 41
2

NUnit, MSTest, etc. all do pretty much the same thing. However, I find NMock indispensable.

NMock or any mocking package is not unit testing, but it makes it so much easier to do unit testing that it might as well be.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dan Blair
  • 2,399
  • 3
  • 21
  • 32
2

I used to use NUnit, but I switched to MbUnit since it has more features.

I love RowTest. It lets you parametrize your tests. NUnit does have a little bit better tool support though. I am using ReSharper to run MbUnit tests. I've had problems with TestDriven.NET running my SetUp methods for MbUnit.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lance Fisher
  • 25,684
  • 22
  • 96
  • 122
1

I like MbUnit, er, Gallio. Most importantly to me is having good tools support inside Visual Studio. For that I use Resharper, which has an MbUnit test runner. A lot of folks seem to like TestDriven.NET as their test runner as well.

Brett Veenstra
  • 47,674
  • 18
  • 70
  • 86