This is a step-by-step tutorial to create your first MbUnit test fixture. (Note for NUnit, csUnit user: it is the same syntax).
Create a new class MyFirstTest, and tag it with the attribute TestFixture. This will tell MbUnit that this class contains tests to be executed.
MyFirstTest
using MbUnit.Core.Framework; using MbUnit.Framework; [TestFixture("This is my first test")] public class MyFirstTest { }
At this point, MyFirstTest does not have any test. Let's add a method that check that 1+1 = 2. To do so, we add the method OnePlusOneEqualTwo. In the test methods, you can use the assertion checks provided by the Assert static helper class:
OnePlusOneEqualTwo
[TestFixture("This is my first test")]public class MyFirstTest{ [Test] public void OnePlusOneEqualTwo() { Assert.AreEqual(2, 1+1, "This is an error message"); }}
The signature of OnePlusOneEqualTwo is important, it must be
public void MethodName(void);
Once you have compiled the assembly, launch the MbUnit gui. Drag and drop the dll or use context menu to load the test assembly. The tree of available tests should instantly appear on the window. The GUI scans the loaded assembly for types tagged with TestFixture attribute and populates the tree. The namespace are reflected into nodes in the tree.
Hit run to launch the tests. When a test is run succesfully, the background of it's tree icon is turning green, this color propagated to the parents. However, if a test fails, the icon turns red and the parents are also turned red.
To have informating about a failed test run, click on the node that failed and take a look at the exception.
Page rendered at Friday, August 29, 2008 12:16:26 AM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.