I'm making the transition from NUnit to XUnit (in C#), and I was writing some "Integrated Tests" (ITs) that I don't necessarily want the test runner to run as part of my automated build process. I typically do this for manually testing, when the full end to end process might not work because of environmental factors (missing data, etc.)
In NUnit, you could mark a test with the Explicit attribute and it would just get skipped by the test runner (unless you marked the test with a specific Category attribute and told the test runner to target that category explicitly).
Does XUnit have a similar way to exclude tests from the test runner?
The only unit test currently implemented is the ValidPassword() method. This method is decorated with the Fact attribute, which tells xUnit that this is a test.
xUnit uses the [Fact] attribute to denote a parameterless unit test, which tests invariants in your code. In contrast, the [Theory] attribute denotes a parameterised test that is true for a subset of data. That data can be supplied in a number of ways, but the most common is with an [InlineData] attribute.
The MSBuild runner in xUnit.net v2 is capable of running unit tests from both xUnit.net v1 and v2. It can run multiple assemblies at the same time, and build file options can be used to configuration the parallelism options used when running the tests.
One way to do it: add " --logger=trx" to the "dotnet test" command and then use the build step "Process xUnit test result report" from the "xUnit plugin". Use the option "MSTest-Version N/A (default) Pattern" and set pattern to "*/. trx". This is the answer!
Jimmy Bogard solved this with a nice RunnableInDebugOnlyAttribute. See this blog post: Run tests explicitly in xUnit.net
public class RunnableInDebugOnlyAttribute : FactAttribute { public RunnableInDebugOnlyAttribute() { if (!Debugger.IsAttached) { Skip = "Only running in interactive mode."; } } }
I think I found it. Apparently, you can modify your [Fact]
attribute like so: [Fact(Skip="reason")]
. This will skip the test, but you'll have no way of running it manually without modifying the attribute back to normal.
I'll keep looking for a better way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With