Kyle Baley - The Coding Hillbilly

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Test SetUp Methods, or "How to make yourself public"

Here's a little sidebar that I bet you didn't know. Actually, that was probably more accurate at my old site where my readership measured on a more, shall we say, intimate, scale.

Anyway, I recently converted a project from NUnit to MbUnit just because I felt like it. (Oh, I'm kidding. I have reasons. Boring but valid ones. So don't sic the alt.net police on me.) In the past, that has involved adding the assembly reference for MbUnit, then performing a global search and replace of the appropriate using statement. Perhaps cleaning up the different Assert syntax but in general, it's a pretty painless process.

This time, I got null reference errors in all tests in several class and to make a long story short (don't get used to it, I don't do it often), I traced it to the SetUp method:

    [ SetUp ]
    protected void SetUp( )
    {
        // Do stuff
    }

Notice that it is protected, which apparently makes it all but invisible to MbUnit. I switched it to public and my world is fully tested again.

Initially, I thought it might be worthy of a bug report. But here is kind of what I typed out:

Hey dudes! You got yerself a fine 'n dandy little product here. But I got meself some tests here someone was nice enough to write out for me in NUnit and when I converted them to MbUnit, they done gone failed on me 'cause the SetUp method is protected even though... the tests themselves are...ummm... y'know...public...

Here's where I started to feel a little silly and considered that maybe the MbUnit folks knew what they're doing when they wrote the product (although I wouldn't mind it handling nullable types a little differently).

So I guess I don't really make this long story all that shorter. The Hillbilly is nothing if not contradictory.

Kyle the Taciturn


Posted Fri, Dec 14 2007 7:04 AM by Kyle Baley
Filed under: ,

[Advertisement]

Comments

dan » Test SetUp Methods, or "How to make yourself public" wrote dan » Test SetUp Methods, or "How to make yourself public"
on Fri, Dec 14 2007 7:58 AM

Pingback from  dan » Test SetUp Methods, or "How to make yourself public"

Jonathan de Halleux wrote re: Test SetUp Methods, or "How to make yourself public"
on Fri, Dec 14 2007 5:16 PM

You should simply report that as a bug to mbunit. There's no reason why they won't not support protected setup method (although it's conceptually wrong).

Jeff Brown wrote re: Test SetUp Methods, or "How to make yourself public"
on Tue, Dec 18 2007 6:17 PM

We've considered supporting non-public setup methods, tests, and other things before.  Code-wise, it's a tiny change.  I'm more concerned about making sure this is really a practice we would like to support / encourage.

The basic assumption is that anything you want the test framework to see should be exposed to it, publicly.

However, if you can make a good case for different behavior, then I encourage you to file a request for enhancement over here: code.google.com/.../list

(And you'll probably get your wish in the MbUnit v3 timeframe.)

Cheers!

Kyle Baley wrote re: Test SetUp Methods, or "How to make yourself public"
on Wed, Dec 19 2007 6:53 AM

I'd go along with Jeff on this. If it's conceptually wrong, then that's reason enough not to support it. But as he mentioned, if you can make a case for it, which I clearly cannot in this case since my reason is "the previous team made the setup method protected by accident", then it sounds like they're amenable to adding the feature in.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?