How to make a test fail if it takes too long?

19

I'm using MSTest which is the default unit testing platform in visual studio and I have this test here:

    [TestMethod]
    [ExpectedException(typeof(InvalidOperationException))]
    public void Board_nao_destroi_unidades_flutuantes()
    {
        var ctor = new Construction();
        Board.Unities.Add(ctor);
        Board.DestroyAllUnities();
    }

He's waiting for an exception to pass but instead he goes into a loop and delays the other 92 tests. What is the way of saying that if my test takes a certain amount of milliseconds it will fail?

    
asked by anisanwesley 12.04.2014 в 15:34
source

1 answer

10

As the MSDN Web site ( link ), just use the Timeout attribute.

[TestMethod(), Timeout(80)]
public void MyTestMethod()
    
answered by 12.04.2014 / 15:37
source