【发布时间】:2022-08-19 13:02:20
【问题描述】:
有时我的管道由于超时而在 Azure DevOps 上失败。它显示如下消息:
中止测试运行:超过 2700000 毫秒的测试运行超时
有些测试比预期的要多,但我不知道它们是哪些测试。所以,我知道每次测试不应该超过 2 分钟,我想设置一个超时。我不想为每个测试添加超时属性,并且需要在新创建的测试上添加超时属性。
我想为我的测试设置默认超时。超时后,我想看看失败的测试。经过一番研究,我发现它不支持:https://github.com/nunit/nunit/issues/1040
我找到了一种解决方案,但看起来不太好: 我在 SetUp 中启动 Timer 并在 TernDown 上停止它:
System.Timers.Timer timer; public System.Timers.Timer Timer { get { if (timer == null) { timer = new System.Timers.Timer(); timer.Interval = 120000; timer.Elapsed += Timer_Elapsed; } return timer; } } void Timer_Elapsed(object sender, ElapsedEventArgs e) { Timer.Stop(); Assert.Fail(\"Timeout\"); } [SetUp] public void Setup() { Timer.Start(); } [TearDown] public void TernDown() { Timer.Stop(); }它正在工作,但如果测试时间超过 2 分钟,它不会立即失败。
有没有人有同样的问题并有解决方案?