Andrew Stopford's Weblog

poobah

News

Articles

MbUnit Folks

Old Blogs

MbUnit v3 alpha 3

Jeff announced the release of Gallio alpha 3 yesterday, my time constriants at the moment meant I missed blogging Alpha 2 back in March but that release was a massive release in terms of features and the work that Jeff, Julian, Graham, Mark, Ben and the rest of the team have put in.

I have talked about Gallio before but as a re-cap, Gallio is described best on the website "The Gallio Automation Platform is an open, extensible, and neutral system for .NET that provides a common object model, runtime services and tools (such as test runners) that may be leveraged by any number of test frameworks", What does that mean, well unit test frameworks such as xUnit.net, NUnit, Pex and MSTest can plugin into the framework (and Gallio supports them all) or frameworks like MbUnit v3 use it directly. It's runners then use that framework and Gallio has the largest set of runners of any unit test framework to date.

  • GUI (Icarus)
  • Console (Echo)
  • TD.NET
  • R#
  • VSTS
  • CCNet
  • Powershell
  • MSBuild
  • NAnt

The runners them selfs are very rich, those who remember the ZaneBug framework will remember how rich it's GUI was and that is something we have aimed for in Icarus with great use of layouts and display information. So now you can take your framework of choice and reuse them across the Gallio platform.

Related directly to MbUnit is the change to the parameterized testing, this has had some heavy work done in make things a little simpler and far more flexible. With this kind of testing now added to Xunit.net, NUnit and csUnit there are lots of different ways you can go about it, the following is a reprint from Jeff's announcement.

 A test can now be parameterized in any of the following ways:

  • Adding a method parameter to a test method.
  • Adding a generic method parameter to a test method.
  • Adding a constructor parameter to a test fixture.
  • Adding a field to a test fixture.
  • Adding a writable property to a test fixture.
  • Adding a generic type parameter to a test fixture.

Correspondingly data-source attributes can be specified on any of the following code elements:

  • Test methods.
  • Test method parameters.
  • Test method generic parameters.
  • Test fixture types.
  • Test fixture constructors.
  • Test fixture constructor parameters.
  • Test fixture fields.
  • Test fixture properties.
  • Test fixture generic parameters.

So there are many choices, but each choice is quite simple.

Here are a few interesting combinations.

A basic "Row"-test.

CHANGE !! - : The [RowTest] attribute is not needed anymore and has been eliminated.

[TestFixture]
public class Fixture
{
    [Test]
    [Row(3, 4, 5, true)]
    [Row(1, 2, 3, false)]
    public void Test(int a, int b, int c, bool expectedResult)
    {
        Assert.AreEqual(expectedResult, Math.IsPythagoreanTriple(a, b, c));
    }
}

CHANGE !! - A generic "Type"-test.

Note: The [TypeFixture] attribute is not needed anymore and has been eliminated.

[TestFixture]
[Row(typeof(List<int>))]
[Row(typeof(LinkedList<int>))]
public class Fixture<T> where T : IList<int>, new()
{
    [Test]
    public void Test()
    {
        T list = new T();
        list.Add(123);
        Assert.AreEqual(1, list.Count);
    }
}

CHANGE !! - A combinatorial test.

Note: The [CombinatorialTest] attribute is not needed anymore and has been eliminated.

[Test]
public void Test([Column(0, 1)] int a, [Column("a", "b")] string b, [Column(false, true)] bool c)
{
    // Test something with the specified combination.
    // Will be executed 8 times total.
}

CHANGE!! - A pairwise test.

Only tests all combinations of pairs of values.  Can yield a significant reduction in test cases compared to ordinary combinatorial tests while still obtaining great coverage.  See also: www.pairwise.org.

[Test, PairwiseJoin]
public void Test([Column(0, 1)] int a, [Column("a", "b")] string b, [Column(false, true)] bool c)
{
    // Test something with the specified combination.
    // Will be executed only 4 times instead of 8.
}

NEW !  - A CSV data source.

Just one of many external data sources to be implemented.

[Test]
[CsvData(ResourcePath="CsvDataTest.csv", HasHeader=true)]
public void ImplicitlyScopedResourceWithHeader(decimal price, string item)
{
    Log.WriteLine("{0}: {1}", item, price);
}

The data itself should be stored in an embedded resource called "CsvDataTest.csv".  We just create a file with that name in the same folder as the test class and then set its Build Action property to Embedded Resource in Visual Studio.

Item, Price
Apples, 1.00
Bananas, 1.50
Cookies, 2.00

Note the changes to TypeFixture and CombinatorialTest, also note Factory is not included, if you use this with combinatorial tests I'd like to hear from you. The Pairwise testing is something new to v3 and I'll cover in more detail in a future post. If you have further questions, things you want to see them also let me know.

Please also note that Jeff sat down with Scott Hansleman, Brad Wilson (XUnit.net), Charlie Poole (NUnit) and Roy Osherove to talk about the past and future of unit test frameworks in .NET at the recent ALT.NET event, Jeff does talk about Gallio and it is well worth a listen. I do hope that in the future the discussion thrown open wider to other folks that are central to the topic, such as Jim Newkirk, Peli de Halleux, Manfred Lange and others.

Comments

azamsharp said:

You guys are awesome!!!!!

MbUnit ROCKSSSSS

# May 14, 2008 8:26 PM

Jeff Brown said:

You missed the MSBuild and NAnt runners.  :)

Also, fear not, the [Factory] attribute will return in Alpha 4.

# May 14, 2008 8:38 PM

Peli said:

The old CombinatorialTest was already a pairwize implementation? What's new? :)

# May 15, 2008 12:18 AM

andrewstopford said:

Point taken Peli, I've edited the post to reflect that, the style is new and as much as I am aware the pairwisejoin is new. Unless I missed that in v2's inner depths, I'll double check next your online :)

# May 15, 2008 4:38 AM

andrewstopford said:

I did Jeff, edited the post to reflect that :)

# May 15, 2008 4:38 AM

Mr. Sustainable said:

I began my work as a web developer with little concern for testing other than to see if IE or IIS threw any errors. Now, I assist with applications used in government work and testing is a big deal. Platforms such as Gallio help bridge the gap and shorten a journey which typically is quite uncomfortable for geeks like the one I am.

# May 15, 2008 8:52 AM

Jeff Brown said:

Peli is correct.  Pairwise was already in MbUnit v2.  We're using a new algorithm and completely different syntax for v3 though.

Actually, in MbUnit v2 the pairwise join was the default for [CombinatorialTest].  This actually led a few people to conclude that MbUnit was "broken".

So in MbUnit v3 the default join when there are multiple data sources present is now a cross-product.  You can override the join by adding an attribute like [PairwiseJoin], [CombinatorialJoin] (default), [SequentialJoin] or create your very own if you wish.

# May 15, 2008 7:57 PM

andrewstopford said:

Great stuff Jeff :), I think this needs a post all of it's own.

# May 16, 2008 4:00 AM

Jeff Brown said:

I agree.  Maybe you could write one... ;)

Also check out named data sources and binding attributes...

# May 16, 2008 2:52 PM

Apostolis Bekiars said:

What about sequence attribute?

Also cannot run test using R#4 am i missing something?

# June 11, 2008 5:11 AM

Jeff Brown said:

Sorry, the R# plugin model is version sensitive.

The next update (in a few days) will fully support the final release of R# 4.0.

# June 12, 2008 5:18 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)