MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

Update: There's a new Unit test framework called XUnit.NET. More info here. 

MbUnit is gaining some momentum as one of the nicest unit testing frameworks for .NET out there. I just came out as an RC2 release with many new features an enhancements, including dull support for NUnit 2.4 Asserts - which is a big deal.

The two coolest features that draw people to using it are:

  • [Rollback] attribute that automatically rolls back any changes to the database that were made during that test method (using a method I developed with COM+ 1.5)
  • [RowTest] attribute that allows declaring one test with several inputs (acting as several tests).

 

I also like MbUnit's extensibility model with is largely different than that of NUnit's and is easier to conform to when writing new attributes.

MbUnit is also one of the topics that I continually have a dilemma about using. Since its not the de-facto standard out there, I always feel there's a chance of it being frozen in mid development, making all those who depend on it frozen along with it.

[Update: Andrew, one of the leads on mbUnit,  makes some good points on why he thinks this is far from happening - which is reassuring, and I'd like to hold out longer befomre making a final call on it's "frozeability".]

I still recommend people to use NUnit as the standard. You can do a lot with NUnit (as well as the rollback attribute - See XtUnit for that). When you get used to it, then I suggest you check out MbUnit. you'll have the tools to whether you really can't live without it.

As long as there are two primary contenders in the unit testing world for .NET (NUnit and MbUnit - don't even get me started on Team System Unit Tests I discuss them in a bit) - there will always be that dilemma and the situation will always be a bit confusing for newcomers into this world.

If your heart is set on using MbUnit (and it is a good platform - I'd use it in a heart beat if a client was using it that I was consulting to) - I recommend using TestDriven.NET along with the unit tests. It just makes it much easier (plus you don't have to worry about any custom UI to run them in - it runs NUnit and MbUnit tests with no problems).

What about Team System unit testing?

For now the unit tests framework in team system and VS 2005 cannot be the de-facto standard for several reasons:

  • It sucks too much right now. They have waay too many bugs in them (excepted exception attribute especially broken
  • It doesn't have enough features and asserts to support the most common cases
  • It's not free for everyone to use ( you can't even use it with the VS express editions - shame on you!)
  • It requires VS 2005 to run (no separate run-time UI - although there is a command line)

A good unit testing solution should solve at least these four basic points in order to be considered as a candidate for a de-facto framework. Not even mentioning wide user acceptance : team system does not live up to its hype right now.

The only good thing going to it is that if you use Team Foundation server you can run the unit tests you wrote more easily as part of the automated build - which you can also very easily achieve if you work with any other framework such as NUnit by using a custom build action. While out of the box experience is important, and should not be dismissed easily, I do tend to still use NUnit even with Team System - as I tend to get better features, more stability and a wider range of possibilities for running my unit tests that way.

Published Saturday, September 23, 2006 8:51 PM by RoyOsherove

Comments

Saturday, September 23, 2006 9:45 PM by Tomas Restrepo

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

I would agree with the Team System Stuff. Besides the points you mention, a unit testing framework should also be fast; team system is extremely slow (compared to NUnit, at least). I certainly plan on taking a look at mbUnit, though the truth is I'm a very happy NUnit user, overall.
Sunday, September 24, 2006 3:29 AM by Plip

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

I'm a recent MBUnit convert, I love the row test functionality - every time one of the users breaks a method I can add another attribute and hey presto that's tested for too.

I used NUnit a lot and found it too restrictive.

Sunday, September 24, 2006 6:41 AM by Michal Talaga

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

I have recently went through the pain of using Microsoft's Unit Testing framework and guess what: it does not support inheritance as I have described here: http://vaultofthoughts.net/TestMethodInTheAbstractClass.aspx
Sunday, September 24, 2006 11:39 PM by Kent Boogaart

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

I haven't used mbunit yet and confluence is down atm so I can't check the doco. It sounds to me like mbunit requires a database to execute against. I have tried hard to avoid external dependencies in my unit tests. Indeed, I have set up my current project to use nunit and SQLite and run all database tests against an in-memory database. I suppose I could do the same with mbunit . . . and possibly get more features. Will have to check it out.
Monday, September 25, 2006 3:12 AM by RoyOsherove

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

Kent: MbUnit doest *not* require any kind of DB to execute tests (nor does any other unit test framework except the ones that are DB-Specific like SQLUnit or DBUnit etc...

However, it can *support* using a db for some tests.

As for not using a DB as an external dependency - that's a long time argument.

Personally I believe that when you write a data access layer, you should purposly have integration tests rather than simple unit tests that check against the database, since the DB contains logic constructs such as constraints, sprocs, triggers etc..

more on this here:

http://weblogs.asp.net/rosherove/articles/dbunittesting.aspx

Roy.

Monday, September 25, 2006 5:27 AM by Andrew Stopford's Weblog

# Roy on MbUnit

Roy talks about the various unit test frameworks and in particular talks about MbUnit. One of Roy's

Monday, September 25, 2006 6:27 AM by ISerializable - Roy Osherove's Blog

# The future of unit testing tools - MbUnit, NUnit, NMock and FIT

After I posted that I still recommend NUnit over MbUnit, and reading Andrew's response regarding how

Monday, September 25, 2006 7:49 AM by Dave

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

I'm not sure why you worry about "frozeability" if the application does what you need to do and has an extensible framework. Unless you are doing some really crazy stuff, or the tool you are using has some serious bugs, what else do you need from it? I guess what I'm saying is - if it does what you need to do now, it'll probably do at least the majority of what you need it to do for the forseeable future. And if its Open Source, you can always pick it up and add your own functionality to it yourself when your needs aren't being met.
Monday, September 25, 2006 4:05 PM by Mike Gale

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

My comments: 1) Use MbUnit first. 2) If you decide to change, conversion to NUnit is easy. Though row tests will expand to bulkier coding. (Conversion both ways is easy!!) 3) With the rate new versions come out it's likely that different projects use different versions. 4) I saw a blog comment that NUnit was thinking of adopting MbUnit features, I haven't followed up on that. 5) A test framework that is bundled with only some versions of VS seems nutty. (As it's not as good a blessing though.) Ultimately I suggest that it's more important for Express users. (I'm assuming TS/Pro etc. users can more easily bolt in some other test framework.)
Monday, September 25, 2006 6:25 PM by OJ

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

It's not free for everyone to use ( you can't even use it with the VS express editions - shame on you!) It's not supported in VS 2005 Pro either. Looks like you need a Team System install for it to be supported. I've used NUnit until now, but after some of the buzz I've been hearing about MbUnit, I think I might have to give it a spin. Cheers.
Monday, September 25, 2006 8:49 PM by Jeff Atwood

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

> I do tend to still use NUnit even with Team System - as I tend to get better features, more stability and a wider range of possibilities for running my unit tests that way. Note that if you do this, none of your test metrics will go in the VSTS data warehouse. Your list of "waaay too many bugs" in VSTS unit testing sounded a lot more like "Roy Osherove wants everything to work *exactly* like nUnit". Which is fine, but that's not exactly the same thing, now is it? ;)
Monday, September 25, 2006 9:14 PM by RoyOsherove

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

Jeff: There's a difference between having features that work differently and having features that don't work at all (ExceptedException attribute does not actually assert on the expected test message, you can't have tests in an abstract test class and more).

And yes, I think that any unit testing system that claims to be a good solution shoudl at least have the same basic feature set of NUnit asserts and attributes.

Would you accept anything less?

Roy.

Monday, September 25, 2006 10:42 PM by Ash

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

We were using NUnit for Unit testing. We got the copy of Team system with VS2005, so we converted to Team system. But after using for 5 months we were so sick of it(Bugs, No seperate UI, Tied to VS, etc) that we changed all tests back to Nunit. Now its NUnit all the way.
Tuesday, September 26, 2006 10:32 AM by Colin Jack

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

In response to the bit about bugs in VSTS unit testing, I agree completely. I've had loads of issues with the unit testing support in VSTS but haven't been able to log a lot of them as they're intermittent and some seem to be to do with integration with other things (possibly including TestDriven.NET). I've logged a few MS Feedback requests about MbUnit as I want to use it with VSTS, but couldn't seem to get the two to play nice: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=165554 http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=165564
Tuesday, September 26, 2006 2:33 PM by Rodney

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

You mentioned TestDriven.Net. I happen to have stopped using TestDriven.Net when Resharper 2.0 was released as it has and TestRunner. This only works for C# at the moment and no I do not work for jetbrains. http://www.jetbrains.com/resharper/features/unitTesting.html
Wednesday, September 27, 2006 9:02 AM by robinz

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

hehe. MbUnit is better than NUnit. MbUnit supply lots of new features, such as data driven testing, set of test cases... MbUnit will be the do-facto standard if it continue developing new & useful features. And, Resharper of JetBrain will support MbUnit soon.
Thursday, October 26, 2006 11:49 PM by tschwallie

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

Zanebug at http://www.adapdev.com/zanebug/index.aspx should open some eyes.
Thursday, November 30, 2006 9:52 AM by Gary

# re: MbUnit vs. NUnit Vs. Team System Unit Testing - Choosing a unit test framework

I've never used MBUnit, just because all companies I've worked at so far have used NUnit. I am in a position in a new company to introduce unit testing, and even though the company is using Team Foundation Server throughout I am steering away from that. What would MBUnit give me over NUnit?

As an aside, you can replicate MBUnit's RowTest attribute using NUnit 2.4's extensibility feature (and use the extensibility do more general programmatic Data-Driven NUnit testing). (I blogged about this earlier in the year up on http://taumuon.blogspot.com/2006_06_01_taumuon_archive.html , I do need to get it finished and updated to work with NUnit 2.4 beta 2).

Wednesday, August 29, 2007 4:15 PM by ISerializable - Roy Osherove's Blog

# Team System Unit Testing May finally be "OK"

All I can say is, It's about time . I'm getting tired of apologizing for the Microsoft Team System Unit