Timeout in c# tests

2019-07-19 00:24发布

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
  }
}

2条回答
Deceive 欺骗
2楼-- · 2019-07-19 00:43

If possible, use the TestCleanUp method in order to do work after the test if it is subject to timeouts.

查看更多
太酷不给撩
3楼-- · 2019-07-19 00:57

Finally is executed always, doesn't matter if u have try/catch/ block, it is executed when any of those are finished

查看更多
登录 后发表回答