我有一个测试需要运行超过 1 分钟(VS2008、MSTest,测试是从 VisualStudio 启动的):
const int TestTimeout = 1;
[TestMethod]
[Timeout(10*60*1000)] // 10 minutes
public void Login_ExpirationFail_Test()
{
IAuthenticationParameters parameters = new AuthenticationParameters(...);
LdapAuthentication auth1 = new LdapAuthentication();
IAuthenticationLoginResult res = auth1.Login(parameters);
Assert.IsNotNull(res);
Assert.IsFalse(string.IsNullOrEmpty(res.SessionId));
const int AdditionalMilisecodns = 400;
System.Threading.Thread.Sleep((TestTimeout * 1000 + AdditionalMilisecodns) * 60);
LdapAuthentication auth2 = new LdapAuthentication();
auth2.CheckTicket(res.SessionId);
}
此测试在“运行”模式下完成,并显示“测试‘Login_ExpirationFail_Test’超出了执行超时期限”。错误消息,在“调试”中 - 它工作正常。
我看到很少有与从命令行启动测试相关的类似问题。
我怎样才能让我的测试在“运行”模式下工作?
Thanks.
答案很简单:属性值应该是常量,而不是表达式。
Change
[Timeout(10*60*1000)]
to
[Timeout(600000)]
解决了一个问题。
编辑:对答案的评论引起了我的注意,我最初在答案中犯了一个错误(将“60000”写为超时值)。在我的源代码中,我有 6000000,这个值很有帮助。答案最近已更正
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)