Question

I have mstest TestClass that contains 35 tests now and that might grow. Methods tested are often recursive (so there might be bug causing infinite loop), so I want to set timeout for those tests.

Is there a way (ideally an attribute) to set same timeout for all tests at one place? TimeoutAttribute can only be used with methods, not classes. And I really don't like copying same TimeoutAttribute 35 times.

Alternatively, can I create my own Attribute that can be used with class and that marks every method in that class with specified attribute?

Was it helpful?

Solution

You need to do this through the test runner configuration. (More details can be found here).

To set the test run time-out for all tests using the tests settings file

  1. Open Solution Explorer.
  2. In the Solution Items folder of your solution, double-click the test settings file. (The Configuration Settings dialog box appears.)
  3. Choose Test Timeouts.
  4. Check Abort a test run if its total execution time exceeds:
  5. Set the test run time-out value, in hours, minutes, and seconds.
  6. Choose Save and then choose Close.

For this setting to take effect, the test settings that you edited must be the active test settings. For more information, see How to: Select the Active Test Settings from Microsoft Visual Studio.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top