Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSTest: how to increase test time

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.

like image 550
Budda Avatar asked Nov 05 '10 20:11

Budda


People also ask

Which is better NUnit or MSTest?

The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.

Does TestInitialize run for each test?

TestInitialize and TestCleanup are ran before and after each test, this is to ensure that no tests are coupled. If you want to run methods before and after ALL tests, decorate relevant methods with the ClassInitialize and ClassCleanup attributes.

How do I run a MSTest unit test?

To run MSTest unit tests, specify the full path to the MSTest executable (mstest.exe) in the Unit Testing Options dialog. To call this dialog directly from the editor, right-click somewhere in the editor and then click Options.

What is the difference between MSTest and xUnit?

MSTest is concerned, the biggest difference between xUnit and the other two test frameworks (NUnit and MSTest) is that xUnit is much more extensible when compared to NUnit and MSTest. The [Fact] attribute is used instead of the [Test] attribute.


2 Answers

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

like image 79
Budda Avatar answered Oct 17 '22 10:10

Budda


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

[Timeout(TestTimeout.Infinite)]
like image 13
Sebastian Castaldi Avatar answered Oct 17 '22 11:10

Sebastian Castaldi