XUnit ignore a test unless specifically triggered
Asked Answered
V

3

25

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!

Voltammeter answered 22/5, 2019 at 3:18 Comment(1)
Possibly related: https://mcmap.net/q/539704/-can-you-mark-xunit-tests-as-explicitFacetiae
W
20

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.

Welby answered 31/3, 2021 at 6:43 Comment(1)
This does not answer the question, specifically that what is requested is the ability to be able to skip it when the tests are run wholesale, but not when they are run individually. This answer will skip them when they are run individually.Bilodeau
B
1

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.

Butt answered 13/10, 2022 at 4:55 Comment(0)
S
0

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
Stow answered 19/6 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.