Visual Studio 2015 또는 2017에서 단위 테스트를 찾지 못함
2016-10-19 편집 :
원래 질문은 XUnit 테스트 러너의 VS2015 CTP6 관련 문제에 관한 것입니다. 여러 가지 상황에서 발생할 수있는 Visual Studio의 단위 테스트 검색과 관련하여 훨씬 광범위한 문제가 있음을 알 수 있습니다. 나는 그것을 반영하기 위해 내 질문을 정리했다.
나는 또한 비슷한 문제가 나타날 때 오늘날에도 여전히 사용하는 스크립트를 내 대답에 포함시켰다.
다른 많은 답변도 VS 테스트 러너의 복잡성을 더 잘 이해하는 데 도움이되는 것으로 입증되었습니다. 사람들이 여전히 솔루션을 공유하고 있다는 점에 감사드립니다!
원래 질문 2015-04-10 :
어제부터 Visual Studio Test Explorer는 내 프로젝트에 대한 테스트를 찾지 않습니다. 건물 후 녹색 로딩 바도 표시되지 않습니다.
Visual Studio 테스트 탐색기로 이동하여 "모두 실행"을 클릭하거나 테스트 방법을 마우스 오른쪽 단추로 클릭하고 "테스트 실행"을 선택하면 출력 창에 다음이 표시됩니다.
Could not load file or assembly 'Microsoft.VisualStudio.Web.ProjectSystem, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
나는 윈도우 10에서 Visual Studio 2015 CTP 6를 실행하고 프로 기술 미리보기, 10041. 닷넷 프레임 워크 버전은 상관하지 않는 것 빌드 - 그것의 발생 4.0
, 4.5.2
및 4.6
.
다음 테스트 프레임 워크를 사용해 보았고 모두 동일한 동작을 제공합니다.
Microsoft.VisualStudio.QualityTools.UnitTestFramework v14.0.22609.0
xunit v2.1.0-beta1-build2945
와xunit.runner.visualstudio v2.1.0-beta1-build1051
NUnit v2.6.4
와NUnitTestAdapter v2.0.0
비슷한 것으로 보이는 GitHub (xunit)에서 문제를 발견 했습니다 : xunit 팀 의이 의견으로 # 295 발견 된 테스트를 얻을 수 없습니다 :
Visual Studio 2015 CTP 5는 xUnit.net뿐만 아니라 일반적으로 단위 테스트를 수행하는 많은 사람들에 의해 중단 된 것으로보고되었으므로 작동하지 않을 것으로 예상됩니다.
또한 Visual Studio의 러너 캐시를 정리했는지 확인하십시오. 손상된 경우 Visual Studio는 삭제 될 때까지 영구적으로 오작동합니다. 캐시를 지우려면 Visual Studio의 모든 인스턴스를 종료 한 다음 % TEMP % \ VisualStudioTestExplorerExtensions 폴더를 삭제하십시오 (정직하게도 % TEMP %에서 삭제할 수있는 모든 항목을 삭제해도 손상되지는 않습니다).
폴더를 삭제하라는 제안을 시도했습니다 %TEMP%\VisualStudioTestExplorerExtensions
. 불행히도 문제가 해결되지 않았습니다.
나는 ReSharper에서 실제로 것으로 나타났습니다 입니다 몇 가지 테스트를 발견 할 수. xunit이 아닌 VS 및 NUnit 테스트에서만 작동합니다.
정리해야 할 일종의 임시 폴더 또는 캐시 폴더가 있어야하지만 Visual Studio에는 많은 폴더가 있으며 원하지 않는 부작용없이 삭제할 수있는 것은 아닙니다.
놀랍게도 %TEMP%
디렉토리 에있는 임시 파일을 지우면 문제가 해결되었습니다.
참고 :이 경로는 일반적으로 C:\Users\(yourusername)\AppData\Local\Temp
@ Warren-P가 포함되어 있으므로 %temp%
시작 메뉴에 넣거나 "파일 탐색기"를 시작 %temp%
하여 주소 표시 줄에 입력 하여 임시 폴더로 이동할 수 있습니다 .
코드가 x64로 컴파일되어 기본 프로세서 아키텍처를 X64로 활성화해야 할 수 있습니다.
Test > Test Settings > Default Processor Architecture > X64
NUnit 테스트 어댑터 2/3 가 VisualStudio에 설치되어 있는지 확인하십시오 .
(Tools>Extensions and Updates )
올바른 프로세서 아키텍처가 선택되어 있는지 확인하십시오.
(Test>Test Settings>Default Processor Architecture)
2016-10-19 (PowerShell 스크립트) 편집
이 문제는 여전히 그렇습니다. 필자는 관련 캐시 / 임시 폴더 / 파일을 자동으로 지우는 작은 PowerShell 스 니펫을 작성했습니다. 장래 독자들을 위해 여기에서 공유하고 있습니다.
@(
"$env:TEMP"
"$env:LOCALAPPDATA\Microsoft\UnitTest"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\1033\SpecificFolderCache.xml"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\1033\ProjectTemplateMRU.xml"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\ComponentModelCache"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\Designer\ShadowCache"
"$env:LOCALAPPDATA\Microsoft\VisualStudio\14.0\ImageLibrary\cache"
"$env:LOCALAPPDATA\Microsoft\VisualStudio Services\6.0\Cache"
"$env:LOCALAPPDATA\Microsoft\WebsiteCache"
"$env:LOCALAPPDATA\NuGet\Cache"
) |% { Remove-Item -Path $_ -Recurse -Force }
미리 Visual Studio를 닫고 나중에 재부팅하는 것이 좋습니다.
TEMP 폴더를 삭제하는 것이 필요하지 않을 수 있으며 경우에 따라 원하지 않는 경우도 있으므로 TEMP 폴더를 먼저 지우지 않고 시도해 보는 것이 좋습니다. 를 생략하십시오 "$env:TEMP"
.
원래 답변 2015-04-12
Visual Studio 관련 temp / cache 폴더를 철저하게 정리 한 후에 문제가 "해결되었습니다".
모든 것을 하나씩 살펴보고 그 사이를 테스트 할 시간이 없었기 때문에 불행히도 실제로 어떤 문제가 발생했는지 알 수 없습니다.
다음은 내가 수행 한 정확한 단계입니다.
- 닫힌 Visual Studio
- 시스템 및 브라우저
temp
파일 / 폴더 를 지우는 데 CCleaner 사용 다음 파일 / 폴더를 수동으로 지우거나 삭제했습니다.
%USERPROFILE%\AppData\Local\assembly
%USERPROFILE%\AppData\Local\Microsoft\UnitTest
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\1033\SpecificFolderCache.xml
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\1033\ProjectTemplateMRU.xml
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\Designer\ShadowCache
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ImageLibrary\cache
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio Services\6.0\Cache
%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache
%USERPROFILE%\AppData\Local\NuGet\Cache
%USERPROFILE%\AppData\Local\Temp
One reason for this problem is that your test class is not public. MSTest only discovers tests from public classes.
In Visual Studio 2015(Update 3) if you want to attach the tests in the test explorer then have to install the NUnit Test Adapter.Download the adapter from Tools->Extension And Updates->Online tab(you have to search for the adapter)->Download. By restarting the Visual Studio you can see the change for the test framework.
I don't have a complete answer to this, but I have determined some things by playing with a test project:
- The
xunit.runner.aspnet : 2.0.0-aspnet-beta4
that appears to be part of the official beta4 aspnet5 release does not work in Visual Studio. - Instead, using
"xunit": "2.1.0-*"
and"xunit-runner.dnx": "2.1.0-*"
packages DO work in Visual Studio. - In order for VS to discover the tests, your project MUST have a SINGLE command named "test" that runs "xunit.runner.dnx". Adding additional commands may break it.
- If your Test Explorer window still ends up empty, REMOVE the "test" command from your project, then re-build the solution, then add the "test" command back to the project.json.
- Clearing all your caches as per @Fred-Kleuver 's suggestion may help, but I haven't done all the steps in isolation, so I'm not sure.
This is current as per VS 2015 CTP 6, using the beta4 releases, not the dailies.
I had an instance where some tests would not be picked up because I had made them async
like the following:
public async void This_IsMy_UnitTest()
The problem was I forgot to make them return a Task
and not void
when I did the switch-over. One would think this would cause an error or failed test but nope. The unit tests in that class were fully ignored and acted like they didn't exist.
It wasn't after about 3 clean and builds + restarting VS.NET
that I saw the test run and fail indicating I forgot to add the Task
return type:
public async Task This_IsMy_UnitTest()
After the update, the unit tests were found and worked correctly. This might be an edge case, but having async
tests for using await
within but not having the signature correct can cause this same issue and it's not the 1st time I've done this.
Go to Nuget package manager and download Nunit Adapter as follow.
I had the same pronlem but the folder "%TEMP%\VisualStudioTestExplorerExtensions" did not exist on my machine so as i read the posts i had the idea to create it and it works. The test explorer is now able to show all my tests. Thanks.
Just restart Visual Studio and in Test Explorer do "Run All" ... All my tests are discovered then.
The solution in my case was just to install the NUnit 3 Test Adapter extension to my Visual Studio 2015.
In my case (Visual Studio Enterprise 2015 14.0.25425.01 Update 3, Resharper 2016.2) I just needed to do a clean solution from the Build menu. Rebuilding the solution then cause the test explorer to "wake up" and find all the tests again.
In my case, MSTest under VS 2015 was ignoring tests with test (i.e. method) names that were longer than 174 characters. Shortening the name allowed the test to be visible. This was determined via guess-and-check by manipulating the test name.
In my case, the problem was "between the chair and keyboard". I had switched to a configuration in the Configuration Manager which did not include my unit test projects on build. Switching back to a configuration (e.g. Debug) which includes all projects fixed the issue.
This probably won't help most people, but someone inexperienced at unit testing had written a test method that returned bool
instead of void
:
[TestMethod]
public bool TestSomething()
Changing the return type to void
fixed the problem.
Ensure you have xunit.runner.visualstudio
package in your test project packages.config and also that was correctly restored.
I know this was not the case of the original question however it could save time for someone like me.
I would just like to add that I found an entirely different solution to the ones above.
I had declared my test class as below:
[TestClass]
class ClassificationTests
{
//unit tests
}
As soon as I added the public
modifier to the class, it worked as expected!
If you're targetting .NET Standard or .NET Core, you need to use the NuGet package for NUnit Test Adapter and not the extension.
It is recommended to install the adapter from NuGet if you are testing .NET Core or .NET Standard projects. The VSIX adapter does not, and will not, support .NET Core because VSIX packages cannot target multiple platforms.
Source: NUnit GitHub Wiki
.
Also check the FAQ there:
My tests aren't showing up in Visual Studio 2017?
- Are you using the NuGet package?
- Are you using version 3.8.0 or newer of the NuGet package?
- Do your tests target .NET Core or the full .NET Framework? (see above)
- Have you added a Package Reference to Microsoft.NET.Test.Sdk?
- Have you restarted Visual Studio? It is still a bit tempermental.
Source: NUnit GitHub Wiki
Popping in to share my solution. I was on Windows 10, Visual Studio 2015, NUnit 3.5, NUnit Test Adapter 3.6 (via NuGet, not the VISX extension) and none of my tests were being discovered. My problem was that in the Tests project of my solution, somehow a shortcut to my "Documents" folder had been created within the project folder. I'm guessing the test adapter was seeing the shortcut and getting hung up trying to figure out what to do with it, resulting in the failure to display unit tests.
Deleting the file \AppData\Local\Microsoft\VisualStudio\14.0\1033\SpecificFolderCache.xml solved the issue for me.
I was also bitten by this wonderful little feature and nothing described here worked for me. It wasn't until I double-checked the build output and noticed that the pertinent projects weren't being built. A visit to configuration manager confirmed my suspicions.
Visual Studio 2015 had happily allowed me to add new projects but decided that it wasn't worth building them. Once I added the projects to the build it started playing nicely.
I resolved it by changing X64 to : Right click on project -> Properties -> Build -> Platform target -> Any CPU
Somehow my project was set to compile as a Static Library (.lib). After changing this to a Dynamic Library (.dll), tests where discovered correctly by Visual Studio 2012.
My Unit Test Project ->
Properties ->
Configuration Properties ->
General ->
Configuration Type
This happened to me because my test project contained an app.config
. It was automatically added by NuGet packages for assembly redirection, but my tests seemed to run fine without it.
See: https://developercommunity.visualstudio.com/comments/42858/view.html.
It was so easy for me to fix the issue as:
- Select your Unit Test Project
- Click on 'Show All Files' button in the Solution Explorer and new temporary files appeared in the file tree of the Solution Explorer within 'obj\x86\Debug'.
- Delete these temporary files and rebuild project.
- Retried to run tests and worked!.
We had the same problem. We have a big VS 2015 solution with multiple C# projects in it and even more test projects.
Resharper's test discovery worked just fine, but VS Test Explorer failed miserably.
Turns out that the projects didn't have the same version of MsTest TestFramework and TestAdapter, and that sometimes they used NuGets and other times good old references, and that is not supported apparently (so much for such an expensive IDE).
Removing all Microsoft.VisualStudio.Test* references and then adding / updating the two MSTest NuGets fixed the problem.
I had the same problem. I just cleaned and rebuilt the project and I was able to see the tests that were missing.
I was struggling with same problem for VSTest framework and my native unit tests.
So, after doing all those things you mentioned before, I removed every occurence of '#' symbol in my solution's directory path. It actually works.
I'm leaving it here for googlers who will find this question in future.
This topic is somewhat outdated, but my solution to the missing Test status in VS2015:
The task-status only shows up on the Debug buildconfiguration. Ofcourse this also makes it impossible to debug your test through the test-explorer.
참고URL : https://stackoverflow.com/questions/29560011/visual-studio-2015-or-2017-does-not-discover-unit-tests
'programing tip' 카테고리의 다른 글
Rails : 페이지 제목을 어떻게 바꾸나요? (0) | 2020.06.05 |
---|---|
쿼리를 통해 MySQL에서 데이터베이스 구조를 얻는 방법 (0) | 2020.06.05 |
백분율 높이 HTML 5 / CSS (0) | 2020.06.05 |
객체를 포함하는 배열을 반복하고 속성에 액세스하는 방법 (0) | 2020.06.05 |
Docker에 볼륨을 추가하지만 하위 폴더는 제외 (0) | 2020.06.05 |