gpt4 book ai didi

unit-testing - MSTest:如何增加测试时间

转载 作者:行者123 更新时间:2023-12-03 00:01:19 27 4
gpt4 key购买 nike

我有一个测试需要运行超过 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’超出了执行超时期限”。错误消息,在“调试”中 - 它工作正常。

我发现很少有与从命令行启动测试相关的类似问题。

如何让我的测试在“运行”模式下可行?

谢谢。

最佳答案

答案很简单:属性值应该是常量,而不是表达式。

改变

[Timeout(10*60*1000)]

[Timeout(600000)]

解决了一个问题。

编辑:对答案的评论引起了我的注意,我最初在答案中犯了一个错误(将“60000”写为超时值)。在我的源代码中,我有 6000000,这个值很有帮助。答案最近已更正

关于unit-testing - MSTest:如何增加测试时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4109781/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com