tags:

views:

278

answers:

3

Dear ladies and sirs.

I am trying to figure out how to write combinatorial test in MbUnit v3. All of the sample code on the web refers to MbUnit v2, which means using 3 attributes:

  • CombinatorialTest
  • Factory
  • UsingFactories

In MbUnit v3 there is no UsingFactories attribute (and the Factory attribute semantics is widely different and CombinatorialTest attribute is no longer needed). So how can I tell which factory method bind to which parameter in the particular unit test method?

Thanks.

+1  A: 

I remember an article from Jeff Brown, the lead developer of Gallio/MbUnit, which talks about dynamic and static factories in MbUnit v3. There is a nice example which describes how to create static and dynamic test factories.

In the other hand, test data factories are easier to create, and provide an interesting alternative to the [Row]-based data-driven tests, which only accept primitive values as input (a limitation of C# for the parameters passed to an attribute)

Here is an example for MbUnit v3. The data factory is here a property of the test fixture, but it can be a method or a field, which may be located in a nested type or in an external type. This is indeed a very flexible feature :)

[TestFixture]
public class MyTestFixture()
{
   private IEnumerable<object[]> ProvideTestData
   {
      get
      {
          yield return new object[] { new Foo(123), "Hello", Color.Blue};
          yield return new object[] { new Foo(456), "Big", Color.Red};
          yield return new object[] { new Foo(789), "World", Color.Green};
      }
   }

   [Test, Factory("ProvideTestData")]
   public void MyTestMethod(Foo foo, string text, Color color)
   {
      // Test logic here...   
   }
}
Yann Trevin
Thanks, but this does not answer the question of CombinatorialTest with UsingFactories. How can one produce a cartesian multiplication of {new Foo(123),new Foo(456),new Foo(789)}x{"Hello","Big","World"}x{Color.Blue,Color.Red,Color.Green} in MbUnit v3?. In v2 it is easy - each parameter of MyTestMethod is attributed with UsingFactories. In MbUnit v3 there is the Column attribute, but it requires the values to be known at compile time, while UsingFactories does not.
mark
A: 

I don't see anything similar to [UsingFactories] in MbUnit's tests, but you could use [Factory] + this combinatorics library to achieve the same result.

Try asking on the MbUnit users group for a confirmation on this.

Mauricio Scheffer
+1  A: 

I have found out, with Jeff's help, that the Factory attribute can simply be used instead of UsingFactories, like so:

public static IEnumerable<int> XFactory()
{
...
}

public static IEnumerable<string> YFactory()
{
...
}

[Test]
public void ATestMethod([Factory("XFactory")] int x, [Factory("YFactory")] string y)
{
...
}

The test ATestMethod will be run on the cartesian multiplication of values generated by XFactory and those generated by YFactory.

mark