c# - 是否有 MBUnit 属性可以按照定义的顺序运行行测试

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

我试过用谷歌搜索这个但是一无所获。基本上,我想按照我定义的顺序运行每一行。例如,如果我有这个:

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

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

最佳答案

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

The order in which attributes are specified (...) is not significant. For instance, the attribute specifications [A][B], [B][A], [A, B], and [B, A] are equivalent.

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

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

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


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

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

关于c# - 是否有 MBUnit 属性可以按照定义的顺序运行行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3722327/

相关文章:

unit-testing - 单元测试Grails Controller

c# - 如何抑制由我​​无法更改的代码显示的对话框?

c# - 用于 XML 模式扁平化的库

c# - 如何从 hWnd 获取 "Application Name"for Windows 10 Store Apps (e.g. Edge)

ios - Swift 项目的单元测试类

c++ - 从外部调用静态 C 函数

unit-testing - 当仅选择一个时,Resharper 运行所有测试

c# - Selenium Grid 2 - 并行数据驱动测试

mbunit - 无法在 MbUnit + TestDriven 中输出日志消息

c# - 维护响应式 WPF UI