Why is the Visual Studio 2015/2017/2019 Test Runne

2020-01-24 19:06发布

UPDATE: Adding a 2019; the discovery/runner integration mechanism is same as per 2017 & 2015, so the key things that can go wrong are the same.


I've read Why is the xUnit runner not finding my tests, which covers reasons xUnit would never be able to find your tests but my problem is different - I'm confident there's nothing subtle going on with my tests; (they have worked in other environments, this seems to be just my machine) - the Visual Studio Test Runner in Visual Studio 2015 [Community Edition] is simply not showing any of my tests. I'm not doing anything remotely exciting; the tests target xUnit.net v2 on the Desktop.

I've looked in the Output window and am not seeing anything in at all under Test in the Show output from tabs.

30条回答
一夜七次
2楼-- · 2020-01-24 19:55

After spending 2 days... none of the above worked for me. The only "solution" was: Go to project properties -> Build Tab. Then click Advanced button on the right bottom corner of the pane. Change "Debug Info:" to "full" and click OK.

Here are the screen shots: enter image description here

enter image description hereenter image description here

查看更多
SAY GOODBYE
3楼-- · 2020-01-24 19:55

Make sure that your test class is public.

查看更多
ゆ 、 Hurt°
4楼-- · 2020-01-24 19:56

The reason in my case was the target build was not the same between project debugger and test runner. To unify those elements:

  1. Test>Test Settings>Default Processor Architecture. then select either X64 or X86.
  2. Project>(your project)Properties>Build(tab)>platform target.

After they are identical, rebuild your solution then test methods will appear for you.

查看更多
【Aperson】
5楼-- · 2020-01-24 19:58

Install xunit.runner.visualstudio package for the test project

查看更多
走好不送
6楼-- · 2020-01-24 19:58

I can provide a solution for an edge case I ran into a few days ago. It's not gonna be the solution that fits all of the scenarios described above, however, for the edge case I had it fixed it.

I had the same issue with most recent VS 2017 (version 15.5.7) and XUnit 2.3.1. The xunit.runner.visualstudio package was installed, however, the tests didn't show up in VisualStudio's built-in test explorer.

I was working on a legacy project that was targeting .NET framework 4.5. However, beginning with version 2.2. XUnit does not support .NET frameworks lower thant 4.5.2 (see Release Notes - XUnit 2.2: February 19, 2017

Changing the test project's target framework to a version >= 4.5.2 worked for me. You don't have to change the project's version that you're testing, it's just about the test project itself.

查看更多
The star\"
7楼-- · 2020-01-24 19:59

I had the same issue with Visual Studio 2019. Just Installed the following NuGet packages and the issue was solved.

1). xUnit

2). xunit.runner.visualstudio

3). Microsoft.TestPlatform.TestHost

4). Microsoft.NET.Test.Sdk

查看更多
登录 后发表回答