'Defining the order in which tests are displayed and run in Visual Studio

Using Visual Studio 2019 and trying out the MSTest, NUnit and xUnit testing frameworks with C#.

Say I have two methods:

// MSTest
[TestClass]
public class MyTests_MSTest
{
    [TestMethod]
    public void WantedToRunThisFirst()
    {
        // Arrange, Act, Assert...
    }
    
    [TestMethod]
    public void ButThisRunsFirst()
    {
        // Arrange, Act, Assert...
    }
}

Have tried the equivalent tests and syntax in all test frameworks (i.e. MSTest, NUnit and xUnit). Tests are always displayed in the Visual Studio Test Explorer section in alphabetical order (i.e. with ButThisRunsFirst at the top). And when the tests are run, the alphabetic order is used again and ButThisRunsFirst runs before WantedToRunThisFirst.

Tests should be independent so the run order shouldn't really matter, but having the tests listed and run to match the order in the code would be nice.

Is it possible to configure the display and/or run order of unit test methods?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source