I have been using NUnit for a number of years now and more recently started using Team System on a number of projects. As an MVP I get a free copy of Team System so the cost was never an issue. On my most recent project we decided to use Team System because of the very useful built in code coverage (this was before nCover was even revised for .NET 2.0) and because of the new useful assertions (which are now becoming available in NUnit 2.4). I don’t really have any issues with Team System testing, its a good solid unit testing framework.
Recently while getting started on a new side project I thought I would re-examine the unit testing landscape. After reading about how much people like MbUnit, and a quick chat with Phil, I decided to give it a whirl. I was floored. MbUnit is like unit testing on crack. Sure, it has all your basic Asserts and other standard methods, but then on top of it there are some awesome features:
[RowTest]
This is probably the #1 feature to me. Normally when writing unit tests you end up with a number of different tests for various scenarios. For instance I might have (this is all mocked up, ignore any syntax errors, or mock me and point them out in the comments):
1 [Test]
2 public void AddValidUser()
3 {
4 User u = new User();
5 u.Name = “James”;
6 u.Email = “myemail@email.com”;
7
8 u.Save();
9
10 User newUser = User.Retrieve(u.ID);
11 Assert.IsNotNull(newUser, “User not found”);
12 Assert.IsTrue(newUser.Name == u.Name, “Name not saved correctly”);
13 Assert.IsTrue(newUser.Email == newUser.Email, “Email not saved correctly”);
14 }
15
16 [Test]
17 [ExpectedException(typeof(InvalidUserException))]
18 public void AddInvalidUserMissingEmail()
19 {
20 User u = new User();
21 u.Name = “James”;
22 u.Save();
23 }
24
25 [Test]
26 [ExpectedException(typeof(InvalidUserException))]
27 public void AddInvalidUserMissingName()
28 {
29 User u = new User();
30 u.Email = “myemail@email.com”;
31 u.Save();
32 }
33
34 [Test]
35 [ExpectedException(typeof(InvalidUserExperience))]
36 public void AddInvalidUserBadEmail()
37 {
38 User u = new User();
39 u.Email = “mybademail.com”;
40 u.Save();
41 }
I have four tests to test a couple different scenarios for different scenarios with my user object, on a larger object and with more rules I get even more tests. If I add a new required field I have to add it to every test.
The [RowTest] attribute helps put all of this into one easier to maintain test:
1 [RowTest]
2 [Row("James", "myemail@email.com")]
3 [Row("James", "", ExpectedException=typeof(InvalidUserException))]
4 [Row("", "myemail@emai.com", ExpectedException = typeof(InvalidUserException))]
5 [Row("James", "mybademail.com", ExpectedException = typeof(InvalidUserException))]
6 public void AddValidUser(string name, string email)
7 {
8 User u = new User();
9 u.Name = name;
10 u.Email = email;
11
12 u.Save();
13
14 User newUser = User.Retrieve(u.ID);
15 Assert.IsNotNull(newUser, “User not found”);
16 Assert.IsTrue(newUser.Name == u.Name, “Name not saved correctly”);
17 Assert.IsTrue(newUser.Email == newUser.Email, “Email not saved correctly”);
18 }
How freaking sweet is that?
[Rollback]
Instead of manually rolling back database changes this attribute with use Roy’s brilliant method of wrapping it all up in a COM+ transactions.
Jim is also a big fan of the pairwise testing, but I haven’t really used it enough to have an opinion yet. Another cool part is that it all works perfectly with testdriven.net (obviously) and if you use testdriven.net then you can still use Team System code coverage.
If you are starting a new project I would definitely take a good look at MbUnit.
-James

{ 29 comments }
>>Jim is also a big fan of the pairwise testing<<
Heh. I’m a big fan of it simply because it’s such a cool concept. How much have I used it? Uh…
The RowTest is wicked cool, as is the Rollback feature. I think ZaneBug is also looking at supporting MbUnit — ZaneBug’s a terrific test runner with lots of shiny toys.
Hey James,
Thank you very much for the heads up on MbUnit..i’ve been a strong follower of NUnit but now i think i may have to have a serious look at MbUnit instead..
especially love the RollBack feature…
Eeeexcelent. Another convert! My work here is done. BWAHAHA.
Thanks James. Note that using info in Roy’s post here: http://weblogs.asp.net/rosherove/articles/dbunittesting.aspx, it’s very easy to get the COM+ 1.5 rollback working in NUnit, too.
Additionally, using .NET 2.0, you can use simpler, lighter-weight System.Transactions functionality to achieve the rollback, as I describe in my blog post here: http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!155.entry
That said, I do believe I’ll be starting a new unit-testing effort soon, and I am impressed enough to give MbUnit a shot. Thanks again.
I love MBUnit and agree with everything you say here.
What I’ve always thought would be cool is if you could specify the inputs and it would run through all permutations, so if I have something that takes 2 bools, the test suite would pass TT,TF,FT,FF, automatically. With strings it could pass an empty string, null string, and a list of specified inputs. Int’s would pass 0, min.int, max.int, etc..
You get the idea. It seems like RowTest is about half way implements of this idea, I’m sure this idea is coming down the pipe line somewhere. Its still an awesome step forward
Thanks for the short but clear explanation, I’ll definately check this out
.
Nunit is better
Kevin U – that is exactly the Pair Wise (or Combinatorial) testing that James refered to. Basically, create your test case, create an IEnumeration per test case parameter, and run. It will run every combination of parameters. Cool, huh?
hello – nUnit is better? How so? MbUnit is way less code and as much functionality. Please don’t bash something especially if you don’t give any rationale.
Mbunit is the worst framework ever. Nunit is better!!!
iv used Zanebug too and this seems to be the best. Mbunit is a dull framework. Some half decent features…
Has Mbunit got support for .NET forms or ASP?
Iv been in the IT industry for 15 years and therefore do not appreciate such rude comments…
Cheers
CsUnit wins the race!!!
Mbunit ranks last!!!
No,
If you want to be taken seriously leave your real name and provide constructive comments.
-James
Ok which one would you choose …giving reasons and support for your claim…
I prefer Nunit!!!
Zanebug tears Mbunit to pieces…its the difference between me and you
When is Zanebug going to support Mbunit? What evidence is available that this will happen??? I agree with Mark Zanebug is a great tool.
However… Mark your first choice keeps changing in all your posts. Do you prefer all of them??? Can someone give me a better indication of what to use. Zanebug, Mbunit, Nunit or CsUnit.
Go Unitdomain beta 1.1!!!
This is a newcomer on the testing framework. Proper version will be out soon. It integrates all the frameworks!!! Iv got the beta from a mate. Seems well good!!!
“No”, or Mark Gilkes – whoever you are.
If you stopped repeatedly posting nonsense with nothing to back it up, perhaps some people would take you seriously.
Your comments reek of “CounterStrike FTW!!!” type post from kids. Blatant fanboy-ism. It’s annoying at best.
“I prefer NUnit”, “MbUnit ranks last” or “worst ever” and such only shows great bias and unobjectivity on your part.
Not like you’d provide anything to backup your opinion either. The fact *you* prefer another unit testing framework (for no particular reason apparently) doesn’t make it better.
MbUnit has some great new features. RowTests and RollBack are great, no one can deny that (pairwise testing also looks tremendously useful to me). That doesn’t necessarily make it the absolute best testing framework, but saying it ranks last (without any backing evidence or anything) is truly ignorant at best. Stop posting stuff like that, you’re only making yourself look stupid (not to mention, constantly contradicting yourself doesn’t look good either: “NUnit is better”, “Zanebug seems to be best” then again “CsUnit wins the race” – right).
Different people have different needs and priorities, and will prefer different things. But your posts were totally pointless.
I don’t think you have a signle clue about what you’re talking about.
For the record, I’m primarily a NUnit user, but MbUnit is looking good, I just might switch to it.
weblogs.asp.net/…/The-future-of-u />
Please visit this!!! Is Zanebug going to support Mbunit???
Can anyone tell me the same as Mark.
“Is Zanebug going to support Mbunit???”
James you seen like you know what you are talking about…can you answer this??? Or can Jim Holmes who originally commented clarity the situation.
All help is much appreciated!!!
Stop posting stupid comments Mark. Can you ignore him James and answer my question above?
“Fools rush in where angels fear to tread”. This is the reason I need to make my choice carefully.
Hello World – What is this???
I am not sure if Zanebug is going to offer support for MbUnit or not. I am sure if it grows enough in popularity they might, but I also know they have some pretty serious dependencies on NUnit. (I think some of the NUnit code is even in Zanebug)
-James
Zanebug or Nunit??? What would you choose?
Yes, we’re planning to integrate MbUnit w/ the Zanebug GUI, so that you can run MbUnit, Zanebug and Nunit tests all within the Zanebug GUI. We’re still working out what needs to be done, so it may be a little while.
In the meantime, I’ll be adding Row Testing to Zanebug, since I’ve gotten a lot of requests for it.
Should have something for that in the near future.
have a great day!
Liverpool Rules!!!
MbUnit Rulz – You having a joke!!!
How do you run Mbunit tests using the GUI? I can only make it work using testdriven. Help needed!!!
I cant even run Mbunit tests. I did add assembly and pointed it at the debug dll but doesnt work. Error message!!! HELP!!!
HOW DO YOU DO ROWTEST IN VB.NET?????
MbUnit is a great solution for unit testing n-tier apps at the BLL level. Love the CollectionAssert class.
Keep up the great work guys.
Comments on this entry are closed.