22

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!

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
keenns
  • 863
  • 4
  • 14
  • 26

2 Answers2

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.

Sandeep Kumar
  • 751
  • 1
  • 6
  • 7
  • 13
    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. – Josh Mc Apr 12 '21 at 01:18
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.

Michelle
  • 11
  • 1