0

I have written a sample .Net Framework Test Application program in C++ which contains 3 methods Test1,Test2,Test3 (using MSTest Framework). If I use VSTest.Console.exe to execute the test cases in release mode, the order of execution of test cases are getting reversed.,i.e.,Test3,Test2 and then in Test1.If I build the project in Debug mode the order is Test1,Test2,Test3

I tried to prioritize the test cases by adding the below lines before every test method , but the output is still same.

BEGIN_TEST_METHOD_ATTRIBUTE(TestMethod1)
            TEST_OWNER(L"OwnerName")
            TEST_PRIORITY(2)
END_TEST_METHOD_ATTRIBUTE()

Link :https://learn.microsoft.com/en-us/visualstudio/test/how-to-use-microsoft-test-framework-for-cpp?view=vs-2022

can any one help me , how to retain the order of execution of test cases when the project is build in release mode.. Thanks in advance!

Minxin Yu - MSFT
  • 2,234
  • 1
  • 3
  • 14
Dev
  • 21
  • 1
  • 2
  • 2
    You should have order independent test cases anyway. Tests should succeed in any order you run them (randomizing the order is even considered to be a good thing). If test do depend on some precondition then that should be setup in a test fixture (and not by a previous test). So my advise is to refactor your tests to be order independent. – Pepijn Kramer Jul 07 '22 at 05:04
  • Does this answer your question? [Controlling execution order of unit tests in Visual Studio](https://stackoverflow.com/questions/20711300/controlling-execution-order-of-unit-tests-in-visual-studio) – Minxin Yu - MSFT Jul 08 '22 at 08:23
  • @MinxinYu-MSFT , Thanks for your reply . I'm trying to invoke the project from a script , i have tried to create the playlist file , but not sure how to use that in script as default one and execute the test sln. – Dev Jul 10 '22 at 13:34
  • Did the playlist work? `how to use that in script as default one and execute the test sln` This is another question. Posting a new thread will be better. – Minxin Yu - MSFT Jul 13 '22 at 06:12
  • @MinxinYu-MSFT yeah the playlist worked when i executed it manually.need to explore on how to invoke it from the script – Dev Jul 20 '22 at 15:19
  • Hi ,glad to know playlist worked! Please consider answering it and accepting it as an answer to change its status to Answered. See [can I answer my own question..](https://stackoverflow.com/help/self-answer). `need to explore on how to invoke it from the script` Suggest posting a new thread to get more attention. – Minxin Yu - MSFT Jul 21 '22 at 02:21

0 Answers0