Using alternatives in MbUnit v3

I am trying to figure out how to write a combinatorial test in MbUnit v3. The entire sample code on the Internet relates to MbUnit v2, which means using 3 attributes:

  • CombinatorialTest
  • Factory
  • UsingFactories

MbUnit v3 does not have a UsingFactories attribute (and the semantics of the Factory attribute vary widely, and the CombinatorialTest attribute is no longer needed). So, how can I determine which Factory method is associated with which parameter in a particular unit test method?

Thanks.

+4
source share
3 answers

I remember an article by Jeff Brown , lead developer of Gallio / MbUnit , which talks about dynamic and static factories in MbUnit v3. There is a good example that describes the creation of static and dynamic test plants .

On the other hand, test data factories are easier to create and present an interesting alternative to tests based on [Row] data, which accept only primitive values ​​as input (C # restriction for parameters passed to the attribute)

Here is an example for MbUnit v3. The factory data here is a property of the test device, but it can be a method or a field that can be located in a nested type or an external type. This is really 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... } } 
+4
source

I found that Jeff will help that the Factory attribute can simply be used instead of UsingFactories , for example

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

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

+4
source

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

Try to request MbUnit user group for confirmation.

0
source

All Articles