Why is the xUnit Runner not finding my tests

后端 未结 8 1197
陌清茗
陌清茗 2020-11-27 05:25

I have a xUnit.net Test as follows:

static class MyTestClass
{
    [Fact]
    static void MyTestMethod() 
    {
    }
         


        
相关标签:
8条回答
  • 2020-11-27 05:52

    This answer is for VS 2013, but the steps are essentially the same for VS 2012. This applies for running via ReSharper's unit test functionality.

    1. Install the xUnit.net runner for Visual Studio 2013 (be careful running Visual Studio as an Administrator, or the tests may not run when running the IDE as a non-Admin):

      a. From within Visual Studio 2013, go to Tools -> Extensions and Updates -> Online

      b. Search for xUnit.net runner for Visual Studio 2012 and 2013

      c. Then download (install) it. If upgrading to VS 2013 from VS 2012, it is suggested that this be uninstalled, and then re-installed.

      d. Restart Visual Studio.

    2. If ReSharper is installed, install the xUnit.net test runner plugin :

      (NOTE: Since ReSharper 2016.1, xunit support is built in to ReSharper, meaning the xunit plugin is no longer required.)

      a. In Visual Studio 2013, Navigate: Resharper -> Extension Manager.

      b. On the left, select Online.

      c. Search for “xunit.net”. Select the “xUnit.net Test Support”. Click Install.

      d. Restart Visual Studio 2013.

    3. “Clean” the solution

      a. In the IDE, in Solution Explorer, right-click the solution, and choose “Clean”.

      b. Re-compile.

      c. Now, when right-clicking a [Fact] attribute, select Resharper’s “Run Unit Tests” (as opposed to the default “Run Tests”)

    Troubleshooting running with XUnit:

    • If problems running the [Fact] tests with XUnit persist, it might be necessary to manually remove the xUnit package from any/all of the following folders (review content for the xunit DLLs, then delete xUnit folder if found):

      • C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\

      • C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\12.0\Extensions\

    • As for ReSharper, try un-installing and re-installing the xunitcontrib library (xUnit.net Test Support). I have noticed once when un-installing, some error messages flashing past. I grabbed a screen-shot at one point, and it listed:

      • Access to the path C:\Users\<username>\AppData\Local\JetBrains\ReSharper\vAny\packages\xunitcontrib.1.3.0\ReSharper\v8.1\plugins\xunit.dll is denied.
      • ... and the same for the other DLLs in that directory

    To resolve this, delete the C:\Users\<username>\AppData\Local\JetBrains\ReSharper\vAny\packages\xunitcontrib.1.3.0\ directory after uninstalling from Visual Studio, then run Visual Studio as a non-administrator, and re-install via ReSharper (Resharper -> Extension Manager)

    0 讨论(0)
  • 2020-11-27 05:54

    I've been having this issue with .NET Core for a while now where a test class or a test method is not being discovered. The following fix works for me:

    1. Open a command prompt window.
    2. Change to the project directory.
    3. Build the project running the following command:

      dotnet build
      

    NOTE: Building from Visual Studio.NET will not work! <<<<<<<<<<< IMPORTANT!

    1. Run the tests: Test --> Run --> Test All - CTRL+R +A (this will discover the new test(s) - but not run the the new test(s).
    2. Run the tests again.
    0 讨论(0)
提交回复
热议问题