2011/10/14

Announcing Gallio and MbUnit 3.3.1

We are pleased to announce that a new release of Gallio/MbUnit is now available. Thanks to an awesome work made by Graham Hay, we can finally release a version which supports Resharper 6. Please see below or read the release notes for more details.

· Downloads

Please visit the Gallio website Downloads page to get the binaries, or grab them directly from here:

2011/09/17

Announcing Gallio and MbUnit 3.3

We are pleased to announce that a new release of Gallio/MbUnit is now available. This release contains many new features and improvements for MbUnit. Please see below or read the release notes for more details.

· Downloads

Please visit the Gallio website Downloads page to get the binaries, or grab them directly from here:

2011/08/07

Immediate opening for a .NET developer.

In case some readers live in Luxembourg area ("Grande Région"), my team is recruiting a .NET developer (junior or experimented). It's a renewable 6 months temporary contract (CDD) but it might be possible that it become a full-time employee position afterwards (CDI). You may read more about this job and apply to it by visiting the Goodyear EMEA Job Board.

2011/06/24

Running Tests Under Another User in Gallio/MbUnit v3.3

It may be convenient sometimes to run test methods under a user account other than the one running the current test session. For example, you might want to test some security feature and see if it behaves correctly according to the level of credentials of a particular archetypal user.

MbUnit provides a very simple attribute that does exactly that: ImpersonateAttribute. To use it, decorate the test methods (or the entire test fixture) with one or several instances of that attribute and feed them with valid user names, passwords and optionally a domain.

You can find more details and a few samples on the Gallio Wiki.

2011/06/15

Extending MbUnit With Custom Expected Exception Attributes

MbUnit provides several ways to deal with expected exceptions in the user code under test. The most popular one is certainly to decorate the test method with an [ExpectedException] attribute:
[Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Constructs_Foo_with_negative_value_should_throw_exception()
{
new Foo(-123);
}
Conveniently, you can use some built-in attributes to save a few more keystrokes:
[Test, ExpectedArgumentOutOfRangeException]
public void Constructs_Foo_with_negative_value_should_throw_exception()
{
new Foo(-123);
}
Those shortcut attributes are very useful. They significantly improve the readability of the tests by removing two pairs of noisy nested parenthesis.

But what if you want to define your own shortcut attribute for a custom exception of yours? Imagine for example that you use a fancy SpaceTimeBrokenException all over your code. Let's define a custom shortcut expected exception attribute for it. That's very easy with Gallio's extensibility model: you just need to derive from ExceptedExceptionAttribute like this:
using Gallio.Framework.Pattern;
using MbUnit.Framework;

[AttributeUsage(PatternAttributeTargets.Test, AllowMultiple = false, Inherited = true)]
public class ExpectedSpaceTimeBrokenExceptionAttribute : ExpectedExceptionAttribute
{
public ExpectedSpaceTimeBrokenExceptionAttribute()
: base(typeof(SpaceTimeBrokenException))
{
}

public ExpectedSpaceTimeBrokenExceptionAttribute(string message)
: base(typeof(SpaceTimeBrokenException), message)
{
}
}
That's all! Now just put that new class in a namespace accessible from your test project and enjoy it...
[Test, ExpectedSpaceTimeBrokenException]
public void Run_TimeMachine_with_negative_power_should_collapse_the_entire_universe()
{
var timeMachine = new TimeMachine();
timeMachine.Run(-1E10);
}

2011/05/10

More About Custom Data Source Attributes

Some weeks ago, I explained how to extend Gallio/MbUnit with custom data source attributes. The principle is to provide convenient and reusable attributes which feed test methods with data coming from an external source (e.g. file, database, distant service, etc.)

Aleksandr Jones has just written a very nice article in his blog that illustrates the concept. He explains how to create an attribute that grabs test parameters from an OLE/SQL database. The typical usage is the following:
[Test]
[CustomAttribute("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=MikeGarage.accdb;Persist Security Info=False;", "Customers")]
public void CustomAttributeTest(DataRow dataRow)
{
// ...
}

2011/03/01

Extending MbUnit with custom attributes

In a recent post, Krzysztof Kozmic discussed about an efficient way to link a particular test to an issue in a bug tracker. MbUnit provides several useful metadata attributes such as [Category], [Author], [TestsOn] etc. But none is about issue tracking :( Fortunately, the Gallio framework is easily extensible (did I say that already?); let's create such an attribute.

Custom Metadata Attribute

We will first create a new simple metadata attribute. We just need to derive from Gallio.Framework.Pattern.MetadataPatternAttribute and to implement some basic code logic in it.
[AttributeUsage(PatternAttributeTargets.TestComponent, AllowMultiple = true, Inherited = true)]
public class IssueAttribute : MetadataPatternAttribute
{
private readonly int issue;

public IssueAttribute(int issue)
{
this.issue = issue;
}

public int Issue
{
get { return issue; }
}

protected override IEnumerable<KeyValuePair<string, string>> GetMetadata()
{
yield return new KeyValuePair<string, string>("Issue", issue.ToString());
}
}
We can now use that simple attribute and enjoy the information displayed in the test report.
[TestFixture]
public class MyTestFixture
{
[Test, Issue(123456)]
public void MyTest()
{
}
}

Custom Test Decorator

But wait! We can certainly do better. My favorite issue tracker is a fancy web application and I would like to get an hyperlink that leads me directly to that issue. We cannot use Gallio metadata for that purpose because they are only key/value pairs of strings. Therefore it's uneasy to make them hold more interesting data like an URL. We will create a new test decorator instead; and use the powerful test log API to display cool stuff in the report. Let's implement a new test decorator attribute (MbUnit.Framework.TestDecoratorAttribute)
[AttributeUsage(PatternAttributeTargets.Test, AllowMultiple = true, Inherited = true)]
public class IssueAttribute : TestDecoratorAttribute
{
private readonly int issue;

public IssueAttribute(int issue)
{
this.issue = issue;
}

public int Issue
{
get { return issue; }
}

protected override void Execute(PatternTestInstanceState testInstanceState)
{
using (TestLog.BeginSection("Issue"))
{
TestLog.Write("This test is related to the ");
using (TestLog.BeginMarker(Marker.Link("http://MyCoolBugTracker/Issue/" + issue)))
{
TestLog.WriteLine("issue #" + issue);
}
}

base.Execute(testInstanceState);
}
}
Look now at the cool link printed in the test report: