是否有 MBUnit 属性可以按照定义的顺序运行行测试
我尝试用谷歌搜索这一点,但一无所获。基本上,我想按照我定义的顺序运行每一行。例如,如果我有这样的:
[Row("a")]
[Row("b")]
[Row("c")]
[Test]
public void Test(string s)...
我想确保测试 A 在测试 B 之前执行,测试 B 在测试 C 之前执行。
I've tried googling around for this but have found nothing. Basically, I'd like to run each row in the order I defined it. For example, if I have this:
[Row("a")]
[Row("b")]
[Row("c")]
[Test]
public void Test(string s)...
I want to be sure that test A is executed before test B, and test B is executed before test C.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如 C# 语言规范(第375):
因此,您永远不能依赖属性定义的顺序。幸运的是,Gallio/MbUnit 为其大多数属性提供了一个方便的可选参数,从而克服了该语言的限制。您需要使用可选参数顺序。
请注意,
Order
也适用于其他属性。特别是,它可以用在[Test]
上来指定测试在装置中运行的顺序。否则,为了绑定示例中所示的单个测试参数,您可能会发现更容易使用
[Column]
而不是[Row]
;并通过仅用 1 个属性替换 3 个属性来摆脱任何属性排序约束:As specified in the C# language specifications (page 375):
Therefore, you can never rely on the order in which attributes are defined. Fortunately, Gallio/MbUnit provides a convenient optional parameter to most of its attributes which overcomes that limitation of the language. You need to use the optional parameter Order.
Please remark that
Order
works on other attributes as well. In particular it might be used on[Test]
to specify the order in which the tests must run in the fixture.Otherwise, in order to bind a single test parameter as shown in your example, you may find easier to use
[Column]
instead of[Row]
; and get rid of any attribute ordering constraint by replacing 3 attributes by only 1: