问题
Can anyone tell if finally is always executed after a test times out or not.
[Timeout(1000)][TestMethod]
public void test()
{
try
{
System.Threading.Thread.Sleep(2000);
}
finally
{
//do something
}
}
回答1:
Finally is executed always, doesn't matter if u have try/catch/ block, it is executed when any of those are finished
回答2:
If possible, use the TestCleanUp method in order to do work after the test if it is subject to timeouts.
来源:https://stackoverflow.com/questions/13514672/timeout-in-c-sharp-tests