2011/12/23

Dynamic binding for data-driven tests in MbUnit v3

MbUnit v3.3 has been now released for a while and I realize that I have completely forgotten to write about the new nifty features added by our fellow contributor Aleksandr Jones. Aleks had added a couple of very powerful attributes for writing data-driven tests. He had even written some useful documentation in the Gallio wiki. Those attributes provide a seamless way to bind automatically your external data sources (CSV or XML data files) to the test parameters.

Basically you can declare your test parameters as "dynamic" variables and let MbUnit to bind automagically the parameters behind the scene. Of course it also means that the feature is only available for test projects targeting the .NET 4 framework.

Let's consider the following simple comma-separated example data file:

Let's now write a test method which loads the file and gets data from it. We could have used the classic [CsvData] attribute to bind explicitly the parameters. But with the new [FlatFileDataObject] attribute, it's far easier:
Look at how the different properties of the test parameter were bound and printed in the test log.
That's just awesome! Good work Aleks!

2011/12/19

Web Testing with MbUnit and WatiN

A serie of articles of mine have been published recently on developerFusion.com. The articles explain how to use efficiently Gallio/MbUnit and WatiN to test your web applications. You can find already many interesting articles about web testing here and there. What I tried to do is to focus on a few less treated problems like testing on the local host, web pages with AJAX requests, controlling the Visual Studio web application server, etc. Good reading!
A big thank you to Dan Maharry and all the editorial team of developerFusion.com for having reviewed my articles.

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);
}