Setting timeouts for a test suite in mstest
Asked Answered
V

3

6

Is there a way to set timeouts for a whole test suite in mstest, or just for individual tests? I.E., if I want the total running time of the tests in suite X to be no more than 2 minutes, how do I do that?

Vocalise answered 23/10, 2013 at 9:36 Comment(2)
#4110281Shunt
This is for independent tests. I'm looking for a change for a suite.Vocalise
P
2

Add the test settings file and change the timeout settings. Go over link - Specifying Test Settings for Visual Studio Tests

Add test settings files to your solution, and then select the one you want to use. You can add more than one test settings file if you want to be able to switch quickly between different settings.

To set the Test TimeOuts - Do the following

  1. To limit the period of time for each test run and individual tests, choose the Test Timeouts. page in the Test Settings dialog box.

  2. To abort a test run when a time limit is exceeded, select Abort a test run if the total time exceeds and then type a value for this limit.

  3. To fail an individual test if a time limit is exceeded, select Mark an individual test as failed if its execution time exceeds, and type a value for this limit.

Perlie answered 23/10, 2013 at 9:45 Comment(0)
G
9

I think it's better to set the timeout in the TestMethod, Set timeout in TestMethod. This way the timeout set does not affect any other test methods.

Sample code before the public test method:

[TestMethod(), Timeout(120000)] 

The timeout is in milliseconds (msecs), 120,000 msecs = 2 minutes, per original question.

Grefer answered 24/10, 2017 at 0:6 Comment(0)
P
2

Add the test settings file and change the timeout settings. Go over link - Specifying Test Settings for Visual Studio Tests

Add test settings files to your solution, and then select the one you want to use. You can add more than one test settings file if you want to be able to switch quickly between different settings.

To set the Test TimeOuts - Do the following

  1. To limit the period of time for each test run and individual tests, choose the Test Timeouts. page in the Test Settings dialog box.

  2. To abort a test run when a time limit is exceeded, select Abort a test run if the total time exceeds and then type a value for this limit.

  3. To fail an individual test if a time limit is exceeded, select Mark an individual test as failed if its execution time exceeds, and type a value for this limit.

Perlie answered 23/10, 2013 at 9:45 Comment(0)
E
1

With the current version of MSTest, you can do this with <TestSessionTimeout/>, which is an element you need to place in a .runsettings file as described in the linked documentation. The value is in milliseconds.

Etalon answered 15/5, 2024 at 1:14 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.