Scott Hanselman

MbUnit - Unit Testing on Crack

September 20, 2006 Comment on this post [15] Posted in Reviews
Sponsored By

MbUnit is a "better xUnit" that's used by a myraid of folks I respect, including James Avery, Patrick Cauldwell and Phil Haack. It's under very active development, even though I'd once wondered aloud if it was "abandonware." It's decidedly not and it's just got a new facelift to prove it.

Check out James Avery's Post called "I've seen the light and it is called MbUnitr."  I've asked around and everyone has nothing but nice things to say what MbUnit brings to the table. It's NOT just NUnit with some tweaks. James says it's "Unit testing on crack."

Check this out...the test will get called four times, each time with different values passed in, some intending to cause and exception and others not. Very clean and certainly nicer than making a dozen methods like "NegativeTest54".

    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 }

 

It's even got a feature that will rollback database changes, keeping your database fresh after each test run. Sweet. I gotta do a show on Trends in Unit Testing...

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
September 20, 2006 5:12
He has seen the light my friends. Another convert! ;)
September 20, 2006 6:45
Am I the only one that don't find that quite as readable as otherwise good refactored regular test code? Plus, I'm not really all that keen at putting both failure and success tests in the same place like that. But certainly will give it a try, looks interesting!
September 20, 2006 6:56
Crap! I clicked on the link to the new facelift and started to party. Only I've been using the recent version for a little while now... so I got all excited for nothing *sniff*.

The ONLY thing that could make MbUnit better would be if it would somehow magically release assemblies (or pull them in via Shadow Copy) each time it finished a batch of tests. I'm sadly quite an iterative tester at points and find myself constantly wanting to rebuild/tweak/etc, and therefore have to keep unloading and reloading my assemblies in the GUI otherwise I can't build correctly...

But yeah, stellar tool.
September 20, 2006 9:48
I'm very new to TDD and testing so this question may have an obvious answer but doesn't this mix test code and production code?
September 20, 2006 9:50
Ah, I see now that it doesn't, just fooled me.
September 20, 2006 15:18
I'm afraid that I'd have to disagree.... in part.

First, let me say that MbUnit is probably better than NUnit - I use both depending on which features I require.

However, no matter how many facelifts it's had (and it has moved about a few times since I started using it a year ago), I don't think that with the last release being an RC1 in February it can yet be labelled as anything other than Abandonware.

Hopefully, this will be the relocation that spells the beginning of a new development cycle.

Just my thoughts.
September 20, 2006 20:51
hi there,

cool.

TestNG(http://testng.org/doc/ -- java unit testing library inspired from jUnit and NUnit) has been having this feature for a while . Yes, it is very useful.

BR,
~A
September 20, 2006 21:14
Very cool, but...

This is an integration test, not a unit test. The practical importance here is that an external resource is required for tests to pass. When running a unit test suite it is expected that no such setup is required. For example, a new developer should be able to grab code from source tree and execute unit tests with no failures.
September 20, 2006 22:02
Well, just what you see here doesnt tell you if it requires external resources. Usually when I work with this sort of setup I would use a strategy pattern or IOC to tell the user where to retrieve or save itself to. So, for testing purposes I could inject a mock repository.

-James
September 21, 2006 1:29
I am not a contributor to the trunk of the current version or the next v3. I have however helped from time to time with infrastructure and documentation. I have written extensions as well.
There has been work on the next version of MbUnit, version 3.0, going on for a little while. It is very early in the cycle.
Here is some impartial info on the project, you can make a more informed judgement.

Google Groups:
MbUnit.Dev - 62 Members with 60 posts last month
MbUnit.User - 120 Members with 35 posts last month

8 Dev Leaders with rights to Subversion

Here is the Svn FishEye:
http://www.mertner.com/fisheye/browse/MbUnit

4 Devs committing changes in Aug
264 files changes/28 revisions in Aug

To compare to NUnit

Mailing List:
Dev - 138 Members with 32 posts last month
User - 195 Members with 19 posts last month

7 Dev Leaders with rights to Subversion

Here is the Cvs commit list:
http://sourceforge.net/mailarchive/forum.php?forum_id=11797

2 Devs committing changes in Aug
? file changes/12 revisions in Aug
September 21, 2006 18:00
I have been trying out some on the features that nUnit doesn't have. I work mostly in vb.net and have yet to get the RowTest with an ExpectedException to compile. Does anybody have a vb.net example of this? I can use RowTest / Row without problem. It is only when try to add the exception that it fails. This is the C# example from the wiki: [Row(1,0,0, ExpectedException = typeof(ArithmeticException))].

Cheers,

Aaron

P.S. This might be a double post. The page recycled with no indication of success or failure the first time I submitted.
September 21, 2006 20:05
I forgot to mention the bug count stats:

MbUnit has 10 bug reports http://www.mertner.com/jira/secure/Dashboard.jspa
NUnit has 34 bug reports http://sourceforge.net/tracker/?group_id=10749&atid=110749
September 21, 2006 20:11
Aaron,
That is a limitation of VB.NET. If you need help with MbUnit the best place to go is the Google group.
http://groups.google.com/group/MbUnitUser?lnk=oa
or for Devs of MbUnit
http://groups.google.com/group/MbUnitDev?lnk=oa

If you search in the group for your problem I know that you will find a thread dealing with your exact issue.

Smiles,
September 21, 2006 20:51
The facelift mentioned above is not just to the MbUnit home page, but also to the reports and GUI. This should all be included in an upcoming RC2. Unfortunately the interim builds are a little harder to find from the new home page, so you may want to download MbUnit 2.3.71 from here: http://build.mutantdesign.co.uk/builds/MbUnit-2.3.71.exe
Note that this build does not have the issue reported by Jeff Campbell above.

As to the question of "abandonware," I think that if you need to download a new unit testing framework every couple months then something is wrong. New builds were made available, for example, with the release of .NET 2.0 to make it available for that environment. I prefer to see it as a stable product, that people are using the real world.

And yes, some of what makes MbUnit popular is that you can use the same framework for integration testing. Some people might not want to blur this line, and might be philosphically happier with NUnit. A lot of us like MbUnit because it just gives us a way to test whatever we think needs testing.
September 22, 2006 13:47
"As to the question of "abandonware," I think that if you need to download a new unit testing framework every couple months then something is wrong"

I don't think that the lack of new releases is the main reason for the product looking like 'Abandonware', it is the fact that the last release, in February, was an RC.

Maybe I look at things differently, but I definitely expect to have a final release a few months after the last RC, or is that not the case?

Like I said, I think that due to it's feature set, MbUnit probably beats NUnit, and I have duly downloaded 2.3.71 from the link posted ;)

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.