Running xunit.net tests in VSTS

Just an update on this as I've recently also had this issue and couldn't get the VsTest runner to discover my .net Core 2.0 xunit tests.

Note: VsTest runner works fine locally on my machine, but not from VSTS - even though xunit test adapters are there.

In any case, use the .NET Core build task instead - it's pretty easy to use. Basically:

  1. Add .Net Core build task (preview atm)
  2. Select desired .NET Core version
  3. Change command to test
  4. Add path or paths to your test projects - e.g. **/*Tests.csproj
  5. Any additional arguments - e.g --filter "Category!=Integration"
  6. There's also a Publish test results option that'll create trx output file

I had the same issue once I made the switch to xUnit, after lots of trial-and-error and searching I found that the xUnit test runner can only be run in an assembly targeting .NET 4.5.2 or above, otherwise it cannot be loaded (and thus the tests will not be found).

The documentation is a bit vague here, since the Getting Started with xUnit guide doesn't really mention this, it only mentions to create a new class library project "targeting .NET 4.5.2 (or later)".

But this is only for the assembly containing the actual tests, your projects being tested can still target .NET 4.5. In my case I simply switched my test assemblies to target .NET 4.5.2, but all the other projects still target .NET 4.5 and it works very well.