单元测试 – 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);
    }

此测试在“运行”模式下以“Test”Login_ExpirationFail_Test“超出执行超时时间”完成。错误消息,在“调试” – 它工作正常。

我看到与命令行启动测试有关的几个类似的问题。

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

谢谢。

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

更改

[Timeout(10*60*1000)]

[Timeout(600000)]

解决一个问题。

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

相关文章

迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图...
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,...
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定...
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个...
命令模式(Command)命令模式(Command)[Action/Transactio...
生成器模式(Builder)生成器模式(Builder)意图:将一个对...