How can XUnit be configured to show just the method name in the Visual Studio 2015 Test Explorer?

You can also add it with json. In the root directory of your test project add a file called “xunit.runner.json”. Right-click the file, properties. Select “Copy if newer” for copy to Output directory. Then in the file enter this json: { “methodDisplay”: “method” } Note that you may1 require to restart the IDE in order … Read more

How to set the test case sequence in xUnit

In xUnit 2.* this can be achieved using the TestCaseOrderer attribute to designate an ordering strategy, which can be used to reference an attribute that is annotated on each test to denote an order. For example: Ordering Strategy [assembly: CollectionBehavior(DisableTestParallelization = true)] public class PriorityOrderer : ITestCaseOrderer { public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases) where TTestCase : … Read more

xUnit.net: Global setup + teardown?

As far as I know, xUnit does not have a global initialization/teardown extension point. However, it is easy to create one. Just create a base test class that implements IDisposable and do your initialization in the constructor and your teardown in the IDisposable.Dispose method. This would look like this: public abstract class TestsBase : IDisposable … Read more

Why is the xUnit Runner not finding my tests

TL;DR your Test Classes must be public (but your Test Methods can be private and/or static) For reasons of efficiency, the xUnit authors have opted to not use BindingFlags.NonPublic when searching for Test Classes in the runner (the MSIL metadata tables don’t index private(/internal) classes to the same degree hence there is a significant performance … Read more

Pass complex parameters to [Theory]

There are many xxxxData attributes in XUnit. Check out for example the MemberData attribute. You can implement a property that returns IEnumerable<object[]>. Each object[] that this method generates will be then “unpacked” as a parameters for a single call to your [Theory] method. See i.e. these examples from here Here are some examples, just for … Read more