【问题标题】:Is there an MBUnit attribute to run Row tests in the order they were defined是否有 MBUnit 属性可以按照定义的顺序运行 Row 测试
【发布时间】:2010-09-15 22:26:21
【问题描述】:

我试过用谷歌搜索,但什么也没找到。基本上,我想按照我定义的顺序运行每一行。例如,如果我有这个:

[Row("a")]
[Row("b")]
[Row("c")]
[Test]
public void Test(string s)...

我想确保测试 A 在测试 B 之前执行,并且测试 B 在测试 C 之前执行。

【问题讨论】:

    标签: c# unit-testing mbunit gallio data-driven-tests


    【解决方案1】:

    C# language specifications(第 375 页)中所述:

    指定属性的顺序 (...) 并不重要。例如,属性规范 [A][B]、[B][A]、[A, B] 和 [B, A] 是等价的。

    因此,您永远不能依赖定义属性的顺序。幸运的是,Gallio/MbUnit 为其大多数属性提供了一个方便的可选参数,克服了语言的限制。您需要使用可选参数Order

    [Row("a", Order = 1)]
    [Row("b", Order = 2)]
    [Row("c", Order = 3)]
    [Test]
    public void Test(string s)
    {
    }
    

    请注意Order 也适用于其他属性。特别是它可能用于[Test] 以指定测试必须在夹具中运行的顺序。


    否则,为了如您的示例中所示绑定单个测试参数,您可能会发现使用[Column] 而不是[Row] 更容易;并通过仅将 3 个属性替换为 1 来摆脱任何属性排序约束:

    [Test]
    [Column("a", "b", "c")]
    public void Test(string s)
    {
    }
    

    【讨论】:

      【解决方案2】:
      Include 'MbUnit.Framework.TestSequence(1)' and use ProcessTextFixture instead  of TextFixture.
        [ProcessTextFixture]
       public class TestSequeunce
      {
      
          [MbUnit.Framework.TestSequence(1)]
          [TEST]
          public void TestMethod1()
          {
          }
      
          [MbUnit.Framework.TestSequence(2)]
          [TEST]
          public void TestMethod1()
          {
          }`enter code here`
      }
      

      【讨论】:

      • 用一些解释来围绕你的代码sn-p会很好。
      猜你喜欢
      • 2010-11-18
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      • 2016-07-17
      • 1970-01-01
      相关资源
      最近更新 更多