Friday, April 30, 2004

This is a step-by-step tutorial to create your first MbUnit test fixture. (Note for NUnit, csUnit user: it is the same syntax).

Step 1: Create and set-up a project
  • Create a library project (assembly) in your favorite .Net language (here it will be C#).
  • Add the following references:
Step 2: Create a TestFixture class

Create a new class MyFirstTest, and tag it with the attribute TestFixture. This will tell  MbUnit that this class contains tests to be executed.

using MbUnit.Core.Framework;
using MbUnit.Framework;

[TestFixture("This is my first test")]
public class MyFirstTest
{
}
Step 3: Add test methods

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:

[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);
Step 4: Running the tests

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. 

posted on Friday, April 30, 2004 8:43:00 PM UTC  #    Comments [12]
Tracked by:
"Generic cialis online." (Generic cialis.) [Trackback]
"reginald denny" (online) [Trackback]
Monday, June 06, 2005 6:07:06 PM UTC
Seems like calls to web services fail.
TagStar
Monday, June 06, 2005 6:07:07 PM UTC
To clarify, I have a test that makes a web service call that succeeds in nunit, but when I run the same test in <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> it fails.
<br>
<br>Have web services been shown to work in <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a>. I'm getting an exception that is thrown because it detects invalid xml. It has to be that <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> is doing something differently.
TagStar
Monday, June 06, 2005 6:07:07 PM UTC
It appears that web references are not serializable. Unfortunately...
<br>
<br>{&quot;The type System.ResolveEventArgs in Assembly mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 is not marked as serializable.&quot; }
SteveStar
Monday, June 06, 2005 6:07:08 PM UTC
Are you using 2.15.1 ? If yes, could you post a little snippet that shows the bug ? (through issue tracking or mailing list)
Jonathan de Halleux
Monday, June 06, 2005 6:07:08 PM UTC
I've created a example web service and web client in C# that uses <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a>.
<br>
<br><a target="_new" href="http://www.tagenigma.com/qa/mbtestwebservice.zip">http://www.tagenigma.com/qa/mbtestwebservice.zip</a>
<br><a target="_new" href="http://www.tagenigma.com/qa/mbtestclient.zip">http://www.tagenigma.com/qa/mbtestclient.zip</a>
<br>
<br>And it appears to work just fine. It could be that the [Init] code might have not been executing in the previous project. I'll have to investigate further.
TagStar
Monday, June 06, 2005 6:07:09 PM UTC
We ran a few tests of our own. We tried connecting to our own web services in asmx with ver 1.0 and ver 1.1 which both succeeded.
<br>
<br>But when we connect to the dev's web services we encounter this error in <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> that doesn't occur with Nunit.
<br>
<br> at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
<br> at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
<br> at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
<br> at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
<br> at mbtestclient.ExternalBillingSystem.UBIWS.SysHealth() in C:\Documents and Settings\tgraupm\Desktop\mbtestclient\Web References\ExternalBillingSystem\Reference.cs:line 843
<br> at mbtestclient.Class1.Test2() in c:\documents and settings\tgraupm\desktop\mbtestclient\class1.cs:line 42
<br>
<br> at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
<br> at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
<br> at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
<br> at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
<br> at mbtestclient.ExternalBillingSystem.UBIWS.SysHealth() in C:\Documents and Settings\tgraupm\Desktop\mbtestclient\Web References\ExternalBillingSystem\Reference.cs:line 843
<br> at mbtestclient.Class1.Test2() in c:\documents and settings\tgraupm\desktop\mbtestclient\class1.cs:line 42
<br>
TagStar
Monday, June 06, 2005 6:07:10 PM UTC
Hi TagStar,
<br>
<br>Could we move this topic to either the <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> issue tracking or users@mbunit.tigris.org ?
Jonathan de Halleux
Monday, June 06, 2005 6:07:10 PM UTC
Peli's Blog
Monday, June 06, 2005 6:07:11 PM UTC
Perhaps, this thread should be moderated and moved to the issue tracking.
<br>
<br>For a basic web service <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> works. So you could turn the examples I link to into a tutorial.
TagStar
Monday, June 06, 2005 6:07:11 PM UTC
Hello,
<br> This could be kinda funny...but whilst installing <a title="TestDriven.NET" href="http://www.testdriven.net" target="_blank">TestDriven.NET</a>, it said that <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> was bundled in it. So...I installed it ...and no errors.
<br> But the assemblies of <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> were not copied into th GAC. Is it that I should be referencing the assemblies directly from the installed folder or add it to the GAC and then reference it? I am trying to understand the idea behind not putting it in the GAC?
<br>
<br>Thanks in advance
<br>-Sashidhar
Sashidhar Kokku
Monday, June 06, 2005 6:07:12 PM UTC
Sashidhar,
<br>
<br> I was wondering the same thing. I followed the directions to integrate <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> with nant, and while nant recognized the <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> tag, it didn't actually run the <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> tests because of missing assemblies. I dropped all the <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> dlls in the GAC except for <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a>.Tasks.dll and <a title="QuickGraph, 100% C# directed graph library" href="http://mbunit.tigris.org" target="_blank">QuickGraph</a>.Algorithms.Graphviz.dll (neither are strongly named) and now the <a title="MbUnit, Generating Unit Testing and Model Based Testing Framework for .NET Framework" href="http://mbunit.tigris.org" target="_blank">MbUnit</a> tests run.
<br>
<br>Will
Will Gwaltney
Monday, June 06, 2005 6:07:12 PM UTC
Adding assemblies to the GAC requires admin credentials. In order for TD.NET to support non-admin installation, the assemblies are not added to the GAC.
Jonathan de Halleux
Comments are closed.