Can you mark XUnit tests as Explicit?

I am making the transition from NUnit to XUnit (in C #), and I wrote some Integrated Tests (IT), which I don’t necessarily want the test runner to run as part of my automatic build process. I usually do this for manual testing, when the complete completion process to the end may not work due to environmental factors (missing data, etc.).

In NUnit, you can mark a test using an Explicit attribute , and it will simply skip the test runner (if you did not mark the test with a specific attribute and told the test runner to explicitly indicate this category).

Does XUnit have a similar way to exclude tests from a test runner?

+7
c # integration-testing testing
source share
3 answers

You can use the [Trait] attribute for this, for example, in the xunit example , for example,

 [Trait ("Category", "Integration")] 

This project takes it a little further and inherits categories such as unit, integration, etc.

+1
source share

I think I found it . Apparently, you can change your [Fact] attribute as follows: [Fact(Skip="reason")] . This will skip the test, but you will not be able to run it manually without changing the attribute in normal mode.

I will look for a better way.

+7
source share

Jimmy Bogard solved this with a nice RunnableInDebugOnlyAttribute. See this blog post: Run tests explicitly on xUnit.net

 public class RunnableInDebugOnlyAttribute : FactAttribute { public RunnableInDebugOnlyAttribute() { if (!Debugger.IsAttached) { Skip = "Only running in interactive mode."; } } } 
+2
source share

All Articles