Vadim's Weblog

Never stop learning.

Fixture order with MbUnit

Posted by Vadim on April 3, 2007

In my company we have some people who are using NUnit and some are using MbUnit. I’m personally a huge fan of MbUnit. As a company we made a decision to use MbUnit only. Someone at my company had a problem with MbUnit because it would run tests in random order. In his case he wanted to run TestFixtures in specific order. He took advantage that NUnit runs TestFixtures in alphabetical order and named the fixtures in order he wants to run them. For example:

A_Fixture
B_Fixture

N_Fixture

To help to solve his problem I reflected on MbUnit.Framework.dll, and found DependOnAttribute. And that exactly what he wanted.

Here how it works. Let assume that we created four.

A_Fixture
Bad_Fixture
B_Fixture
B_Child_Fixture

[TestFixture]
public class A_Fixture
{
[
Test]
public void Success()
{ }
}

[TestFixture]
public class Bad_Fixture
{
[
Test]
public void Failure()
{
Assert.IsTrue(false);
}

[Test]
public void Success()
{
}
}

[TestFixture]
[
DependsOn(typeof(A_Fixture))]
[
DependsOn(typeof(Bad_Fixture))]
public class B_Fixture
{
[
Test]
public void Success()
{
}
}

[TestFixture]
[
DependsOn(typeof(B_Fixture))]
public class B_Child_Fixture
{
[
Test]
public void Success()
{
}
}

You can see that B_Child_Fixture depends on B_Fixture. B_Fixture at the same time depends on A_Fixture and Bad_Fixture. As you can see one of the tests in Bad_Fixture will fail. As a result B_Fixture and B_Child will not run.

Here’s the result in the MbUnit GUI.

2 Responses to “Fixture order with MbUnit”

  1. Beautiful explanation about the order of fixtures in MBunit..It provides a greater flexibility..

  2. mahesh said

    I am not able to see the dependency in MBUnit unit after adding the “Dependson” for my rowtest

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

 
%d bloggers like this: