32

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

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
devoured elysium
  • 101,373
  • 131
  • 340
  • 557

3 Answers3

31

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.

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
3

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.

Mike de Klerk
  • 11,906
  • 8
  • 54
  • 76
0

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.

Konstantin S.
  • 1,307
  • 14
  • 19