Timeout in c# tests

白昼怎懂夜的黑 提交于 2019-12-11 02:37:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!