keenns
keenns

Reputation: 903

XUnit ignore a test unless specifically triggered

I have 2 xunit tests I want to be ignored when triggering Run All Tests from VS, and to only run if the user ran it/them specifically.

I've tried using [Fact(Skip = "Long test, only run if needed, and run independently")] (or whatever message), however then it shows warnings, and the overall run's result is yellow like so, even though the rest passed:

enter image description here

I've found solutions on here that potentially allow this to be done via Resharper, however we do not have resharper available to us (I know... it sucks). I've also looked into SkippableFacts, but I believe these will lead me to the same result as in the above picture. Not to mention when you try to run it on it's own it always skips as well, and you need to change it to a regular [Fact]

Does anyone know of any possible way to ignore a test unless intentionally, specifically, and individually triggered? Any other paths to try would be really helpful, I'm stumped. Thanks!

Upvotes: 26

Views: 16196

Answers (3)

Andy Brown
Andy Brown

Reputation: 13009

Use traits and filters:

[Fact, Trait("type", "integration")]
public void MyIntegrationTest()
{
}

Filter out using your IDE settings or with the command line:

dotnet test --filter type!=integration

Upvotes: 1

Michelle
Michelle

Reputation: 41

Create playlists in VS (or 'Session' in Rider). One with the tests you always run, and a second one for the tests you only intend to run sporadically.

Upvotes: 1

Sandeep Kumar
Sandeep Kumar

Reputation: 815

In XUnit library you can use Fact or Theory (as the case may be) with the Skip attribute.

[Fact(Skip = "Reason")] or
[Theory(Skip ="Reason")]

This will skip the test and overall result should be green. It is working for me in my Asp.Net Core application.

Upvotes: 21

Related Questions