Program Club

xUnit Runner가 내 테스트를 찾지 못하는 이유

proclub 2020. 11. 22. 20:38
반응형

xUnit Runner가 내 테스트를 찾지 못하는 이유


다음과 같이 xUnit.net 테스트가 있습니다.

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

VS 2012 용 xUnit 플러그인은 다음과 같이 말합니다.

실행할 테스트가 없습니다.

TestDriven.net은 잘 실행 되지만 Ad Hoc에 대해 언급합니다 .

1 개 통과, 0 개 실패, 0 개 건너 뛰기 ( '작업 목록'참조), 0.47 초 소요 (Ad Hoc)

인 TeamCity, xunit.gui.exe그리고 xunit.console.exe및 Visual Studio도 찾을 수 없습니다TestMethod

(내가 xunit.runner.visualstudio설치했고 VS가 몇 가지 테스트를보고있다.)

무엇을 제공합니까?


TL; DR 테스트 클래스 다음과 같아야 합니다 public(그러나 테스트 방법은 다음 private같을 수 있음 static).


효율성을 위해 xUnit 작성자는 BindingFlags.NonPublic실행기에서 테스트 클래스를 검색 할 때 사용하지 않기로 결정했습니다 (MSIL 메타 데이터 테이블은 클래스를 동일한 수준으로 인덱싱 private(/ internal) 하지 않으므로 상대적 효율성에 상당한 성능 차이가 있습니다. 따라서 반사가 달성 될 수 있습니다).

위의 결과로 귀하의 class것이 사실이라는 것은 private픽업되지 않음을 의미합니다.

테스트 방법이 private좋고 static괜찮다 는 사실 -1.0 이후 xUnit은이 두 가지 측면을 모두 지원했습니다.

Visual Studio xUnit Runner 확장 xunit.console.exe(및 GUI), xunitMSBuild 작업, Resharper 및 CodeRush는 모두이를 준수하는 데 일관 적이라는 점에 유의하십시오 (단, 테스트 클래스 (즉, 클래스)가 플래그를 지정하는 데 더 많은 작업을 수행 할 수 있지만 [잠재적으로 간접적으로]- Fact파생 된 주석 포함)은 private)입니다.

TestDriven.net이 테스트를 실행하는 이유는 TestDriven.net의 작성자가 Just Work를 만들기 위해 많은 노력을 기울 였기 때문입니다. 내부적으로 테스트를 실행하기 위해 특수한 Test Runner 래퍼 / 심 (Adhoc Runner라고 함)을 사용합니다. 메서드가 실제로 xUnit.net 실행기를 통해 실행되지 않으므로 부작용이있는 테스트에 입력 한 속성은 트리거되지 않습니다.

특히 NUnit (그리고 나는 MSTest) private reflection을 사용 private한다고 확신합니다. 따라서 클래스 에서 테스트를 선택하기 때문에 이전에 걱정할 필요가 없었던 것 같습니다.

참고 : 이로 인해 활성화 된 부작용 / 트릭 은 테스트 클래스 [및 모든 중첩 클래스]의 모든 테스트 privateSkipping 하는 빠른 방법으로 테스트 클래스 만들 수 있다는 것 입니다. (슬프게도이 행성에서 의도하지 않게 사용 된 사례가 의도적 인 사례보다 훨씬 많습니다!)


이 답변은 VS 2013 용이지만 단계는 기본적으로 VS 2012와 동일합니다. 이는 ReSharper의 단위 테스트 기능을 통해 실행하는 데 적용됩니다 .

  1. Visual Studio 2013 용 xUnit.net 실행기를 설치합니다 (Visual Studio를 관리자로 실행하면주의해야합니다. 그렇지 않으면 IDE를 관리자가 아닌 사용자로 실행할 때 테스트가 실행되지 않을 수 있습니다).

    ㅏ. Visual Studio 2013 내에서 도구-> 확장 및 업데이트-> 온라인으로 이동합니다.

    비. Visual Studio 2012 및 2013 용 xUnit.net runner 검색

    씨. 그런 다음 다운로드 (설치)하십시오. VS 2012에서 VS 2013으로 업그레이드하는 경우이를 제거한 다음 다시 설치하는 것이 좋습니다.

    디. Visual Studio를 다시 시작하십시오.

  2. ReSharper가 설치된 경우 xUnit.net 테스트 실행기 플러그인을 설치합니다.

    ㅏ. Visual Studio 2013에서 탐색 : Resharper-> Extension Manager.

    비. 왼쪽에서 온라인을 선택합니다.

    씨. “xunit.net”을 검색합니다. “xUnit.net 테스트 지원”을 선택합니다. 설치를 클릭하십시오.

    디. Visual Studio 2013을 다시 시작합니다.

  3. 솔루션 "청소"

    ㅏ. IDE의 솔루션 탐색기에서 솔루션을 마우스 오른쪽 단추로 클릭하고 "정리"를 선택합니다.

    비. 다시 컴파일하십시오.

    씨. 이제 [Fact]속성을 마우스 오른쪽 버튼으로 클릭 할 때 Resharper의 "Run Unit Tests"를 선택합니다 (기본값 "Run Tests"가 아님).

XUnit 실행 문제 해결 :

  • XUnit을 사용하여 [Fact] 테스트를 실행하는 데 문제가 지속되면 다음 폴더 중 일부 / 전체에서 xUnit 패키지를 수동으로 제거해야 할 수 있습니다 (xunit DLL의 콘텐츠를 검토 한 다음 발견되는 경우 xUnit 폴더를 삭제).

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

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

  • ReSharper의 경우 xunitcontrib 라이브러리 (xUnit.net 테스트 지원)를 제거하고 다시 설치해보십시오. 제거 할 때 일부 오류 메시지가 깜박이는 것을 한 번 발견했습니다. 한 지점에서 스크린 샷을 찍었는데 다음과 같이 나열되었습니다.

    • 경로에 대한 액세스 C:\Users\<username>\AppData\Local\JetBrains\ReSharper\vAny\packages\xunitcontrib.1.3.0\ReSharper\v8.1\plugins\xunit.dll가 거부되었습니다.
    • ... 그리고 해당 디렉토리의 다른 DLL에 대해서도 동일합니다.

    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)


From http://xunit.github.io/docs/getting-started-desktop.html#run-tests-visualstudio:

If you're having problems discovering or running tests, you may be a victim of a corrupted runner cache inside Visual Studio. To clear this cache, shut down all instances of Visual Studio, then delete the folder %TEMP%\VisualStudioTestExplorerExtensions. Also make sure your project is only linked against a single version of the Visual Studio runner NuGet package (xunit.runner.visualstudio).


I had the same issue in VS2017 RC, .NET core 1.1 project. Updating xunit.runner worked for me,

Install-Package xunit.runner.visualstudio

(As referred to by @Kyle in the comments on the other answer) The same No tests found to run message can result from using NuGet to get xUnit.dll and ending up with version 2.0.0 (which is currently marked as prerelease as some core functionality like discovering of v1 tests etc. has yet to be implemented in that branch).

The resolution in this case is to select Stable Only versions (as opposed to Include Prerelease) in the NuGet package manager.


For me, the combination of my test class and test method names were too long; xUnit appears to have some cap on this combination.

Shortening the name of just the test method allowed xUnit to discover that single test. Shortening the name of the entire class allowed xUnit to discover all tests in the class.

Threshold of class name + method name appears to be 172 characters.


In my case, in order to see any tests, I had to complete the following steps:

(All installed through NuGet Package Manager)

  1. Install xUnit v2.0.50727
  2. Install xUnit.extensions v2.0.50727
  3. Navigate to the following link and follow the steps outlined in the documentation: http://xunit.github.io/docs/running-tests-in-vs.html

I'm using Visual Studio 2013 Premium. (Resharper NOT installed)


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.

참고URL : https://stackoverflow.com/questions/16214684/why-is-the-xunit-runner-not-finding-my-tests

반응형