views:

20

answers:

1

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.

+1  A: 

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)
{
}
Yann Trevin