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

Question:

I am 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();
    }

It is waiting for an exception to pass but instead it loops and delays the other 92 tests. What's the way to say that if my test takes a certain amount of milliseconds it will fail?

Answer:

As the MSDN website says ( http://msdn.microsoft.com/en-us/library/ms243175.aspx ) just use the Timeout attribute.

[TestMethod(), Timeout(80)]
public void MyTestMethod()
Scroll to Top