开发者

Is there an MSTest equivalent to NUnit's Explicit Attribute?

Is there an MSTest equivalent to NUnit's Explicit Attri开发者_高级运维bute?


No, the closest you will get is with the [Ignore] attribute.

However, MSTest offers other ways of disabling or enabling tests using Test Lists. Whether you like them or not, Test Lists are the recommended way to select tests in MSTest.


When you want the test only to assert when ran with the debugger (implicitly run manually I assume) then you may find this useful:

if (!System.Diagnostics.Debugger.IsAttached) return;

Add the line above at the beginning of the method marked with [TestMethod]. Then the test is always ran, but nothing is asserted when there is no debugger attached.

So when you want to run it manually, do it in debug mode.


I am using this helper:

public static class TestUtilities
{
    public static void CheckDeveloper()
    {
        var _ =
            Environment.GetEnvironmentVariable("DEVELOPER") ??
            throw new AssertInconclusiveException("DEVELOPER environment variable is not found.");
    }
}

Use it at the beginning of the tests you want. The test will only run if the DEVELOPER environment variable is set. In this case, the rest of the tests will be executed correctly and the dotnet test command will return a successful result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜