Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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`
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top