MbUnit v3中的UsingFactories替代 [英] UsingFactories alternative in MbUnit v3

查看:96
本文介绍了MbUnit v3中的UsingFactories替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何在MbUnit v3中编写组合测试.网上的所有示例代码都引用了MbUnit v2,这意味着要使用3个属性:

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
  • 工厂
  • 使用工厂

在MbUnit v3中,没有UsingFactories属性(并且Factory属性的语义有很大不同,并且不再需要CombinatorialTest属性).那么如何知道特定工厂测试方法中哪个工厂方法绑定到哪个参数呢?

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?

谢谢.

推荐答案

我记得 Gallio/MbUnit的首席开发人员 ,它讨论了MbUnit v3中的动态和静态工厂.有一个很好的示例,描述了如何创建静态和动态测试工厂.

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.

另一方面,测试数据工厂更易于创建,并且为基于[Row]的数据驱动测试提供了有趣的替代方法,后者仅接受原始值作为输入(传递给的参数的C#限制)属性)

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)

这里是MbUnit v3的示例.数据工厂在这里是测试治具的属性,但它可以是方法或字段,可以位于嵌套类型或外部类型中.这确实是一个非常灵活的功能:)

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...   
   }
}

这篇关于MbUnit v3中的UsingFactories替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆