devoured elysium
devoured elysium

Reputation: 105037

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

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

Upvotes: 32

Views: 6297

Answers (3)

Konstantin S.
Konstantin S.

Reputation: 1495

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.

Upvotes: 0

Mike de Klerk
Mike de Klerk

Reputation: 12328

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.

Upvotes: 4

Mark Seemann
Mark Seemann

Reputation: 233125

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.

Upvotes: 31

Related Questions