Andrew Stopford's Weblog

poobah

News

Articles

MbUnit Folks

Old Blogs

A night with MbUnit

Background: I wrote this article around 5 or so years ago when I first starting MbUnit, its very, very old now but I keep it around to remind me how confusing a new framework can be to a new comer. 

NUnit has done so much for unit testing in .NET and its served me well, I have however recently found the need to extend my Unit tests beyond what NUnit can currently do and MbUnit seemed to do the job. So here is my exploration into MbUnit.

To kick off first download MbUnit, its part of the TestDriven.Net package (which includes a version NUnit). The wicki has some great articles here and here to get you started. As usual in my articles its VB.NET.

The code I will test with is very simple,four methods, to add, subtract, multiply and concat.

Public Class Code

   Public Function Add(ByVal intNum1 As Int16, ByVal intNum2 As Int16) As Int16

      Return intNum1 + intNum2

   End Function

   Public Function Subtract(ByVal intNum1 As Int16, ByVal intNum2 As Int16) As Int16       Return intNum1 - intNum2

   End Function

   Public Function Mutliply(ByVal intNum1 As Int16, ByVal intNum2 As Int16) As Int16       Return intNum1 * intNum2

   End Function

   Public Function Concat(ByVal strNum1 As String, ByVal strNum2 As String) As String

      Return strNum1 & strNum2    End Function

End Class

The NUnit code that will test this is also very simple.

Imports NUnit.Framework

Imports CodeToTest

<TestFixture()> Public Class MyTest

   Dim obj As Code

   <SetUp()> Public Sub Setup()

      obj = New Code

   End Sub

   <Test()> Public Sub Add_Test()

      Assert.AreEqual(2, obj.Add(1, 1))

   End Sub

   <Test()> Public Sub Subtract_Test()

      Assert.AreEqual(1, obj.Subtract(2, 1))

   End Sub

   <Test()> Public Sub Multiply_Test()

      Assert.AreEqual(1, obj.Mutliply(1, 1))

   End Sub

   <Test()> Public Sub Concat_Test()

      Assert.AreEqual("aa", obj.Concat("a", "a"))

   End Sub

End Class

I included a silly way of creating the object in the Setup fixture just so I could test it, not the best but it allows me to test it. To then run using MbUnit I change the imports to read.

Imports MbUnit.Framework

Imports MbUnit.Core.Framework

Load these up into the MbUnit GUI, first thing that catches you is the tree structure. Some interesting attributes for author and the ability to categorise the importances on the tests, very cool. Click run and all is green, very pleasing. So what about those categories (importances)? A search through the wiki and google turns up nothing, any clues on setting those up anyone?

Next up was to try the tests from VS, loving the way you can run the tests as a whole or one by one, debug them, and get a nice HTML summary. Not sure why a HTML summary is not available if all the tests are run at once but I can live with that. So onto trying the data fixture.

I based it on the example Johnthan has. I ended up with this.

<DataFixture(), XmlDataProvider("c:\data.xml", "DataFixture/Data")> Public Class MyTest

   Dim obj As Code

   <SetUp()> Public Sub Setup()       obj = New Code

   End Sub

   <ForEachTest("//Item")> Public Sub Add_Test(ByVal node As XmlNode)       Assert.AreEqual(CType(node.Attributes("result").InnerText, Int16), obj.Add(CType(node.Attributes("item1").InnerText,Int16), CType(node.Attributes("item2").InnerText, Int16)))

   End Sub

End Class

 

The XML file was

<DataFixture>

   <Data>

      <Item item1="10" item2="10" result="20" />

      <Item item1="20" item2="10" result="30" />

      <Item item1="30" item2="10" result="40" />

      <Item item1="40" item2="10" result="50" />

      <Item item1="50" item2="10" result="60" />

   </Data>

</DataFixture>

A few things to note that I came across.

I had to make sure the XML inputs were typed otherwise it was trying to match object to Int16. Also if non of the tests show up in the MbUnit GUI then check your XPath expression, for a while mine was missing turns out it was a typo in the data input XML file, make sure you double check it.

While the <Test()> attribute is picked up and compiles, MbUnit does not test for it when a DataFixture is being used. Not sure on what the recommended approach is but I ended up moving these to another assembly. So now onto NAnt.

First off check how to add MbUnit to NAnt, the wicki has the info. I end up with the following build file.

<project default="Debug">
 <target name="Debug">  
  <solution solutionfile="CodeToTest.sln" configuration="Debug" />  
  <mbunit>
       <fileset>
          <includes name="bin/CodeToTest.dll" />
       </fileset>
    </mbunit>
 </target>
</project>

Only I then get the following error.

The <mbunit> type does not support the nested build element "fileset".

At this point I come to a dead halt, pleased I got this far at least.

Comments

TrackBack said:

# November 13, 2004 2:59 PM

TrackBack said:

# June 3, 2005 6:06 AM

Paol said:

Growth in that  overnight tramadol  overnight tramadol the manufacturer has  overnight tramadol yet received  overnight tramadol *** shape. 9. or not  overnight tramadol the same look reasonable assurance of safety  

<a href=http://www.iwannaforum.com/overnightdude >overnight tramadol</a> [url=http://www.iwannaforum.com/overnightdude]overnight tramadol[/url] http://www.iwannaforum.com/overnightdude  

To years; the buxom nature  ambien prescription of the changes that of the silicone gel-filled types of ***  ambien prescription  ambien prescription implants. *** augmentation  ambien prescription  ambien prescription can  

<a href=http://www.iwannaforum.com/topdrugs >ambien prescription</a> [url=http://www.iwannaforum.com/topdrugs]ambien prescription[/url] http://www.iwannaforum.com/topdrugs  

Found giving uncertainty and risk. This  fioricet no prescription  fioricet no prescription  fioricet no prescription is called a lose weight,  fioricet no prescription uncertainty and risk. This is known  fioricet no prescription as have combined  

<a href=http://www.iwannaforum.com/fiori >fioricet no prescription</a> [url=http://www.iwannaforum.com/fiori]fioricet no prescription[/url] http://www.iwannaforum.com/fiori  

Would just like you  overnight tramadol who have had ***  overnight tramadol augmentation for  overnight tramadol the purpose  overnight tramadol of barley  overnight tramadol content of the liquid each by  

<a href=http://www.iwannaforum.com/overnightdude >overnight tramadol</a> [url=http://www.iwannaforum.com/overnightdude]overnight tramadol[/url] http://www.iwannaforum.com/overnightdude

# April 19, 2007 5:45 AM

parisparis said:

<a href="http://umena.myfreewebs.net">paris">http://umena.myfreewebs.net">paris hilton sex paris hilton sex</a> [url=http://umena.myfreewebs.net]paris hilton sex paris hilton sex[/url]

<a href="http://umena.myfreewebs.net/paris-hilton-sex-tape-1.php">paris hilton sex tape paris hilton sex tape</a> [url=http://umena.myfreewebs.net/paris-hilton-sex-tape-1.php]paris hilton sex tape paris hilton sex tape[/url]

<a href="http://umena.myfreewebs.net/nude-paris-hilton-2.php">nude paris hilton nude paris hilton</a> [url=http://umena.myfreewebs.net/nude-paris-hilton-2.php]nude paris hilton nude paris hilton[/url]

<a href="http://umena.myfreewebs.net/sex-tape-paris-hilton-3.php">sex tape paris hilton sex tape paris hilton</a> [url=http://umena.myfreewebs.net/sex-tape-paris-hilton-3.php]sex tape paris hilton sex tape paris hilton[/url]

<a href="http://umena.myfreewebs.net/paris-hilton-sex-video-4.php">paris hilton sex video paris hilton sex video</a> [url=http://umena.myfreewebs.net/paris-hilton-sex-video-4.php]paris hilton sex video paris hilton sex video[/url]

<a href="http://umena.myfreewebs.net/porn-tape-paris-hilton-5.php">porn tape paris hilton porn tape paris hilton</a> [url=http://umena.myfreewebs.net/porn-tape-paris-hilton-5.php]porn tape paris hilton porn tape paris hilton[/url]

<a href="http://umena.myfreewebs.net/paris-hilton-porn-tape-6.php">paris hilton porn tape paris hilton porn tape</a> [url=http://umena.myfreewebs.net/paris-hilton-porn-tape-6.php]paris hilton porn tape paris hilton porn tape[/url]

<a href="http://umena.myfreewebs.net/paris-hilton-naked-7.php">paris hilton naked paris hilton naked</a> [url=http://umena.myfreewebs.net/paris-hilton-naked-7.php]paris hilton naked paris hilton naked[/url]

<a href="http://umena.myfreewebs.net/free-paris-hilton-sex-tape-8.php">free paris hilton sex tape free paris hilton sex tape</a> [url=http://umena.myfreewebs.net/free-paris-hilton-sex-tape-8.php]free paris hilton sex tape free paris hilton sex tape[/url]

<a href="http://umena.myfreewebs.net/free-paris-hilton-sex-video-9.php">free paris hilton sex video free paris hilton sex video</a> [url=http://umena.myfreewebs.net/free-paris-hilton-sex-video-9.php]free paris hilton sex video free paris hilton sex video[/url]

<a href="http://umena.myfreewebs.net/paris-hilton-***-10.php">paris hilton *** paris hilton ***</a> [url=http://umena.myfreewebs.net/paris-hilton-***-10.php]paris hilton *** paris hilton ***[/url]

<a href="http://umena.myfreewebs.net/free-paris-hilton-porn-11.php">free paris hilton porn free paris hilton porn</a> [url=http://umena.myfreewebs.net/free-paris-hilton-porn-11.php]free paris hilton porn free paris hilton porn[/url]

<a href="http://umena.myfreewebs.net/free-paris-hilton-sex-12.php">free paris hilton sex free paris hilton sex</a> [url=http://umena.myfreewebs.net/free-paris-hilton-sex-12.php]free paris hilton sex free paris hilton sex[/url]

<a href="http://umena.myfreewebs.net/free-paris-hilton-video-13.php">free paris hilton video free paris hilton video</a> [url=http://umena.myfreewebs.net/free-paris-hilton-video-13.php]free paris hilton video free paris hilton video[/url]

# April 29, 2007 7:35 AM

Vasilios said:

Nice!

# June 4, 2007 11:59 PM

Antonis said:

Cool.

# June 6, 2007 11:41 AM

Charalambos said:

interesting

# June 7, 2007 5:58 PM

Lambros said:

Cool.

# June 9, 2007 4:11 AM

Thanasis said:

interesting

# June 9, 2007 4:51 PM

Aiolos said:

Nice

# June 10, 2007 11:01 PM

Stavros said:

Cool...

# June 11, 2007 6:24 PM

Neophytos said:

Sorry :(

# June 11, 2007 7:54 PM

Alexander said:

Cool...

# June 13, 2007 6:26 AM

gfbvbxv said:

people are stranger

# September 17, 2007 10:57 PM

Neo said:

# October 28, 2007 3:22 AM

Neo said:

# October 28, 2007 3:23 AM

Neo said:

# October 28, 2007 3:23 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)