MSTest:如何增加测试时间

发布于 2024-09-30 16:17:41 字数 938 浏览 2 评论 0原文

我有一个测试需要工作超过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

羁〃客ぐ 2024-10-07 16:17:41

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

进行更改

[Timeout(10*60*1000)]

[Timeout(600000)]

解决问题。

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

Answer is very simple: attribute value should be a constant, not an expression.

Change

[Timeout(10*60*1000)]

to

[Timeout(600000)]

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

决绝 2024-10-07 16:17:41

除了指定秒数之外,Timeout() 还支持允许无限等待的常量。

[Timeout(TestTimeout.Infinite)]

In addition to specifying the number of seconds, Timeout() supports a constant that allows for infinite waiting.

[Timeout(TestTimeout.Infinite)]
浅笑轻吟梦一曲 2024-10-07 16:17:41

不是具体步骤,但应该为您指明正确的方向:

如果您还没有测试设置文件,则将测试设置文件添加到解决方案中。

打开包含测试设置的配置向导,然后查找控制测试超时的设置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文