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

发布于 2024-09-19 11:46:37 字数 197 浏览 12 评论 0原文

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

[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小霸王臭丫头 2024-09-26 11:46:37

C# 语言规范(第375):

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

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

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

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


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

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

As specified in the C# language specifications (page 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.

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.

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

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:

[Test]
[Column("a", "b", "c")]
public void Test(string s)
{
}
2024-09-26 11:46:37
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`
}
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`
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文