Organizing NUnit Test in a .Net or MonoDevelop Solution

April 14, 2008 at 9:18 pm Leave a comment

When I first use Nunit, I was confused on how to set up Nunit test inside a solution. I can think of several alternatives:

  1. Have Nunit test be in the same project / Assembly.
  2. Same as 1, but use a compiler flag like #ifdebug to filter out the Nunit code during production.
  3. Create a single test project where unit test for all solutions resides. So there is a single “Unit Test” project solution where all of the unit test are stored.
  4. For each project in the solution being tested, create a corresponding test project. So if you have a “Calculation” project, you would have a corresponding “Calculation Test” project that holds all of the unit test for Calculation Project.

Personally, I do not like option 1 because it deploys Nunit code into production. I do not like option 2 because preprocessor macros are error prone. In addition, if you are only testing when the debug flag is true, are you really testing the code?

I prefer option 4 over option 3 because it gives me the flexibility to organize the test and also promote isolation between different tests. If you lump all of the test under the same project, it may be difficult to figure out which test is from which project.

For example, if we want to do a Calculator application, you’ll end up with the following solution structure:

Calculator — Solution for the calculator application

CalculatorApplication — Startup project. Contains the main routine.

CalculatorClass — this is the class code for the calculator.

CalculatorClassTest — this is the unit test for the CalculatorClass.

For each project will have a corresponding unit test project. The unit test project will reference the assembly of the project being tested. The CalculatorApplication just enough code to call the other classes. It is not tested. It may be a pain to setup at first, but it is the most organized and flexible way to organized your unit test.

About these ads

Entry filed under: .Net, Unit Testing. Tags: .

Using Subversion source control with MonoDevelop Running DotNet application under 64-bit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

April 2008
M T W T F S S
« Feb   May »
 123456
78910111213
14151617181920
21222324252627
282930  

Most Recent Posts


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: