Running xunit.net tests in VSTS

孤人 提交于 2019-12-05 03:34:34

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.

Adriaan de Beer

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!