When creating tests with NUnit, they will execute in alphabetical order.
For more info, check out the Official NUnit documentation.
When creating a test case, they should be independent of each other. In the cases of wanting to place slower tests last, grouping similar, or whatever there are a couple of solutions.
As of NUnit 3.2 you can use the
OrderAttribute.
public class TestFixture
{
[Test, Order(1)]
public void FirstTest()
{
Assert.AreEqual(1, 1);
}
[Test, Order(2)]
public void SecondTest()
{
Assert.AreEqual(2, 2);
}
Another workaround for older versions is to use the
TestCase attribute. However, this requires you to input an argument into the function. The
TestName property will act as your sort order.
public class TestFixture
{
[TestCase(1, TestName = "Test1")]
public void FirstTest(int unused)
{
Assert.AreEqual(1, 1);
}
[TestCase(2, TestName = "Test2")]
public void SecondTest(int unused)
{
Assert.AreEqual(2, 2);
}
And for yet another workaround for older NUnit version, you can use the
Category attribute.
public class TestFixture
{
[Test]
[Category("1st")]
public void FirstTest()
{
Assert.AreEqual(1, 1);
}
[Test, Category("2nd")]
public void SecondTest()
{
Assert.AreEqual(2, 2);
}
[Test, Category("3rd"), Description("Optional in-line attribute")]
public void ThirdTest()
{
Assert.AreEqual(3, 3);
}