Search code examples
c#testingvisual-studio-2022mstestxunit

Is it possible to see the order in which tests are run in visual studio?


I have a suite of 800-odd tests in a C# solution. They are using XUnit. The xunit.runner.json demands that the tests be run serially. In other words, there should never be more than one test running at a time.

I am trying to debug a Heisenbug that sometimes fires in one of the tests. I find myself wondering if it might be related to something that happens before the test is run.

Is there a way to see the order in which the tests are run? Or even to see what test was run immediately before my target test?

Obviously it would be possible to modify all the tests to log the name of the test as it starts.

Related question here Is it possible to see the sequence of test run?. But it's 11 years old and does not have an answer that is useful for my situation.


Solution

  • You could run the tests from command line using vstest.console.exe which logs the test names as they are run:

    vstest.console.exe .\path-to-your-test.dll
    

    vstest.console.exe is shipped with Visual Studio and can be invoked from the Developer Command Prompt, or you can find it at %ProgramFiles%\Microsoft Visual Studio\<version>\<edition>\Common7\IDE\Extensions\TestPlatform (for older, 32-bit versions of VS it's under %ProgramFiles(x86)% instead of %ProgramFiles%).

    Obviously if the tests are ran in parallel then the output order is not necessarily correct. But since this is not a problem for you it should be OK.