Jordan
Jordan

Reputation: 1619

Visual Studio: Exclude Project by default when running tests from test explorer

I've added an integration test project to my solution and I'd like to not run them by default when using the test explorer.

The only solution I've come across to isolate these tests is to manually categorize them and choose not to run tests with a particular trait from test explorer. Ideally, I could exclude them so that people on my project don't have to make this choice explicitly.

Thanks!

Upvotes: 3

Views: 1342

Answers (1)

Vlad DX
Vlad DX

Reputation: 4730

There is a special attribute in NUnit to mark your tests that should not be run automatically.

[Explicit]

The Explicit attribute causes a test or test fixture to be skipped unless it is explicitly selected for running.

https://github.com/nunit/docs/wiki/Explicit-Attribute

You just put it on the class or method:

[TestFixture]
[Explicit]
public class IntegrationTests
{
    // ...
}

[TestFixture]
public class UnitTests
{
    [Test]
    public void ShouldNotFail()
    {
         // This will run
    }

    [Test]
    [Explicit]
    public void ManualTest()
    {
        // This will be ignored
    }
}

This is the result:

Test results

Upvotes: 2

Related Questions