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) {
source share