This project is read-only.

Support for MbUnit

Oct 24, 2010 at 3:13 PM
Edited Oct 24, 2010 at 3:30 PM

Hi everybody, this project for fluent unit testing definitions is great!

Do you plan to implement support for MbUnit? I guess it is not so difficult because SharpTestsEx.Factory.AssertExceptionFactory class exists as extension point. However, I do not like the way how it is implemented: the factory method takes the resulting error message as an argument. I would like to have the implementation like this:

namespace SharpTestsEx.Factory
public static class AssertExceptionFactory
public static Exception CreateException(string testDescription, string errorMessage, string expectedValue, string actualValue)
var assertFailureFunc =
new Gallio.Framework.Assertions.AssertionFailureBuilder()
try {
catch (Exception e)
return e;
return null;


Oct 24, 2010 at 3:18 PM

We have already various factories for xUnit, NUnit and MsTest.

AFIK for Gallio the default is enough.

Which is the failure message, with stack-trace, you are seeing in Gallio testrunner ?

Oct 24, 2010 at 3:46 PM

In Gallio report you see "errorMessage". Other information like "expectedValue" and "actualValue" are formatted right as if they came from MbUnit Assert.AreEqual(expectedValue, actualValue, errorMessage).

I must admit that my solution above has to be more general in order to cover features of more complex objects (collections, etc.). I'll do further research for what the signature of CreateException method should be.

Oct 24, 2010 at 3:48 PM

What I'm saying is:

Which is the actual failure message and stack trace you are seeing in Gallio using the SharpTestsEx.dll and a failure test wrote using SharpTestsEx assertions ?

Oct 24, 2010 at 4:14 PM

First sentence of failure message is "errorMessage" in example above. See this MbUnit assert:

Assert.AreEqual(1, 2, "Values are not equal.");

It leads to this message in Gallio report:


"Values are not equal.
Expected Value: 1
Actual Value: 2
Stack Trace: ...


StackTrace comes along with Gallio.Framework.Assertions.AssertionHelper.Verify(assertFailureFunc) if this method call fails.

Well, idea of SharpTestEx CreateException() method is just to create a specific exception if the previous verification (AndAssertion, UnaryAssertition) fails.

My idea is to let the host unit testing framework invoke the verification process. I feel the syntax provided by SharpTestEx pretty nice because it allows me to write the verifications in a clearer way compared to standard asserts. At the same time, it is just syntactic sugar for writing clearer asserts. Hence I would vote for being it a builder for set of asserts and verifications but verification process itself should be the responsibility of host testing framework.


Oct 24, 2010 at 4:28 PM

That is not a SharpTestsEx assertion, that is a MbUnit default assertion.

Your idea was what I was doing in NUnitEx, the ancestor of SharpTestsEx, and believe me that was not with a great result.

Oct 24, 2010 at 4:36 PM

I am not sure whether I got your point. Can you clarify what was the problem with the approach of NUnitEx? I am not familiar with neither history nor features on NUnitEx.

Oct 24, 2010 at 4:40 PM

This are sources of

There you can find what you are looking for but for NUnit.


Now write this


run it with Gallio and let me know which is the failure message completed with stack-trace.

Oct 24, 2010 at 5:18 PM

I went through NUnitEx briefly. It is not how I am thinking of extending SharpTestEx but anyway. I thing I got your point - NUnit asserts are spread out in many places and it would be really terrible to be easily extensible.
Next, I tried the following sample you suggested:
using MbUnit.Framework;
using SharpTestsEx;

namespace SharpTestDemo
public class SharpTestDemo
public void SharpTestEx()
1.Should("Numbers should be equal.").Be.EqualTo(2);
public void MbUnit()
Assert.AreEqual(2, 1, "Numbers should be equal.");

The Gallio report is here:

So the expected and actual values are highlighted and each of the is on one row. I realize that it is just an example of simple assert, but I would like to achieve rich text formatting with SharpTestEx, too. Gallio has many hooks for attaching other tools to integrate to. Thus, my former idea was to have an extension point in SharpTestEx providing full control of verification process.


Oct 24, 2010 at 7:03 PM

"1 Should be Equal to 2" is enough for my taste

The only thing wrong, there, is the presence of "SharpTestsEx.AssertException".

Oct 24, 2010 at 8:00 PM

OK. I must live with the way how SharpTestEx works now then...

Oct 24, 2010 at 8:15 PM

You can fork and make a pull request for a minimal AssertExceptionFactory specific for Gallio