Software Test Timeout in MSTest

I have a situation where I use unit test to execute an external tool that runs a test. From the exit code of the instrument, I can determine if the test passed, failed or failed.

Is there a way that I can crash a unit test that sets the test result to a timeout instead of a failed one?

I tried throwing a TimeoutException, but this has the same result as when using Assert.

Edit: We associate unit tests with test cases in TFS. At the Microsoft Test Center, a test in a test run can have many conditions. One of them is the timeout state. I am trying to fail my test so that it displays correctly in this state and does not fail with unsuccessful test cases.

+5
source share
4 answers

You can set a timeout limit for each test by adding the timeout (milliseconds) in the Test attribute ...

[TestMethod, Timeout(2000)]

The test will fail if it takes more than 2 seconds to complete.

Thanks Marko

+12
source

In unit testing, you have two colors: green and red. There is no timeout color.

So, I think you could manually skip the test in case the timeouts of your external tools are:

Assert.Fail("External tool used to do this test timed out");

The way you detect that your external tools have been calculated will, of course, depend on the external tool you are using and the way it is called from your unit test.

+1
source

"", :

  • Visual Studio
  • Microsoft, Microsoft Test Center tcm.exe(. Tcm)

, , ( "" .)

, "-".

, , , .

+1

, TimeoutException, . TimeoutException UnitTestAssertException.

, :

0
source

All Articles