简体   繁体   中英

"No tests found to run" Xunit test not detected in Test explorer, Visual Studio 2022

As you guys can see on the screenshot, i can run my Xunit test through cmd, however in Test Explorer no test was found.

I have these packages from nuget:

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0-preview-20220726-02" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">

在此处输入图像描述

I have tried the following fix after doing some research on internet:

  1. Deleting.vs folder
  2. Clicked Run all tests in view button
  3. Installing other packages suggested in other posts for similar problem, clean, rebuild
  4. Restart VS, PC. Close and re-open Test Exlorer
  5. Changing from auto to x86/x64

None of above worked. If you have any tips that might fix this for me, please let me know, thank you.

For questions about this Test, you can refer to this link: Dynamic test discovery

Every test class must have the TestClass attribute, and every test method must have the TestMethod attribute.

Visual Studio will put the method with the TestMethod attribute under the class with the TestClass attribute into the Test Explorer (Test Explorer expansion method: Menu bar -> Test -> Window -> Test Explorer )

So it couldn't find my tests because i had no solution, the video i watched created projects through cmd, he explained that in an other video after that.

I am not 100% sure what the problem is, but I agree I had suddenly similar problem in VS2022, that Test Explorer was not showing any tests, but it found my tests. But not showing or executing the tests.

  • Not sure why? But sure I changed fron Xunit.DependencyInhection towards Microsoft.Extensions.DependencyInjection nuget-package as solution.
  • Clean solution? Rebuild your solution? Nope.
  • Execute: dotnet test command => does this work? Yes as refactored code.
  • Did you try to put your computer off and on again? Yes, nope it didn't help.
  • In my case, it was quite simple, just delete all folders as search as "bin" and as "obj" folders from your project folder.
  • Rebuild solution.
  • Voila, all tests are displayed in Test Explorer VS2022

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM