MSTest:如何增加测试时间
我有一个测试需要工作超过 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’超出了执行超时期限”。错误消息,在“调试”中 - 它工作正常。
我看到很少有与从命令行启动测试相关的类似问题。
我怎样才能让我的测试在“运行”模式下工作?
谢谢。
I have one test that needs to work more then 1 minute (VS2008, MSTest, tests are launched from the 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);
}
This test is finished in "Run" mode with "Test 'Login_ExpirationFail_Test' exceeded execution timeout period." error message, in "Debug" - it works fine.
I saw few similar problems linked to launching tests from the command line.
How could I get my test workable in "Run" mode?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案很简单:属性值应该是常量,而不是表达式。
进行更改
以
解决问题。
编辑:对答案的评论引起了我的注意,我最初在答案中犯了一个错误(将“60000”写为超时值)。在我的源代码中,我有 6000000,这个值很有帮助。答案最近已更正
Answer is very simple: attribute value should be a constant, not an expression.
Change
to
resolved an issue.
EDIT: Comment to the answer brought to my attention a mistake I've done originally in the answer (wrote "60000" as timeout value). In my source code I have 6000000 and that value helped. the answer was corrected recently
除了指定秒数之外,
Timeout()
还支持允许无限等待的常量。In addition to specifying the number of seconds,
Timeout()
supports a constant that allows for infinite waiting.不是具体步骤,但应该为您指明正确的方向:
如果您还没有测试设置文件,则将测试设置文件添加到解决方案中。
打开包含测试设置的配置向导,然后查找控制测试超时的设置。
Not specific steps, but should point you in the right direction:
Add a test settings file to the solution if you don't already have one.
Open the configuration wizard with the test settings, and look for the setting that controls the test timeout.