代码之家  ›  专栏  ›  技术社区  ›  Budda

MSTest:如何增加测试时间

  •  22
  • Budda  · 技术社区  · 15 年前

        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);
        }
    

    此测试是在“运行”模式下完成的,并且“测试”的“登录过期失败测试”超过了执行超时时间。“调试”中的错误消息-它工作正常。

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

    谢谢。

    3 回复  |  直到 12 年前
        1
  •  18
  •   Budda    13 年前

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

    改变

    [Timeout(10*60*1000)]
    

    [Timeout(600000)]
    

    解决了一个问题。

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

        2
  •  12
  •   Zanon    9 年前

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

    [Timeout(TestTimeout.Infinite)]
    
        3
  •  0
  •   eglasius    15 年前

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

    使用测试设置打开配置向导,并查找控制测试超时的设置。