Visual Studio 2010 UnitTestAdapter could not be loaded - unit-testing

I have a few dozen VS Solution, each with a a VS Test project in it that I use at work and at home. One day, the tests (in one solution) stopped running, giving me the following error when I run the tests:
The test adapter
('Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter,
Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter,
Version=10.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a')
required to execute this test could
not be loaded. Check that the test
adapter is installed properly. Object
reference not set to an instance of an
object.
It continues to run fine for everyone else on the team, and fine for me at work, but home is a failure. Also, the other solutions' test projects all run fine for me at home, it is just one of them that fails. One other tidbit, we use Moles in all of the tests (again the other moles tests work fine).
I am not seeing much about this error, except for rebuilding the test project. I would rather get to the bottom of this.
Any thoughts?

I had the same problem. Started to have problems after converting our solution from VS2008 to VS2010. For some reason when running the unit tests Visual Studio complained about Unable to find HostAdapter "Moles". Then I tried to download the latest version of Moles Framework (0.94.51023.0) and reinstall it.
Then I received the problem that is described above. All tests with the attribute HostType("Moles") failed with the following error.
The test adapter ('Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') required to execute this test could not be loaded. Check that the test adapter is installed properly. Object reference not set to an instance of an object.
After a lot of searching I found the reason for my problem.
1) I opened the Visual Studio 2010 Command Prompt and typed fuslogvw which starts the Assembly Binding Log Viewer.
2) I went into Settings and checked Log all binds to disk and Enable custom log path.
3) I started one test that used to fail and the Log Viewer logged a lot of files. I opened the most recent log file and for me this one was: Microsoft.ExtendedReflection, Version=0.94.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.HTM
4) The log file describes how Visual Studio tries to find the Microsoft.ExtendedReflection.dll. But for some reason this file can't be located.
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
5) I then remembered that I had Visual Studio 2010 running when installing Moles Framework the previously. So I closed VS2010 down and re-installed it.
6) This seemed to have done the trick
So to make a long story short. The solution for me was to close down Visual Studio and re-install Moles Framework.

I had the same problem. Seems like it began after I started my tests in debug mode Debug Selection and then interrupted execution. When I tried to run my tests after that, I got the same error.
The only thing that helped me, is to run test with Debug Selection again and wait till execution ends. Then tests started to work properly.

Seems to happen when a test is interuppted (Exception thrown, etc.)
To fix, open the web.config of the site and Change this
<add name="HostAdapter" type="Microsoft.VisualStudio.TestTools.HostAdapter.Web.HttpModule, Microsoft.VisualStudio.QualityTools.HostAdapters.ASPNETAdapter, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</httpModules>
to this
</httpModules>
basically deleting the "hostadapter" module ... cause if the test fails unexpectedly it doesn't seem to clean itself up afterwards.

Related

How to run Google tests (C++ unit tests) in a QNX Virtual machine, using resharper?

Currently how I run my unit tests:
I have a visual studio project, which builds a C++ google test (unit test) executable.
I then copy this exe to my Virtual Machine with QNX and run it manually, to get the unit test results.
Can I use resharper to automate this?
Resharper is able to detect and list tests from test file. But on running them, it throws error as it is not able to execute the tests in Windows.
Below is the exact error, I get, on running any of the tests.
ReSharper Ultimate – Error while running unit tests:
Invalid path
Can I set up resharper and Visual studio environment, so that, I can run tests directly from visual studio, which will copy the exe to the Virtual Machine and give me the execution results?
This will avoid me manually copy pasting the exe and running command to execute the tests?
I searched a lot regarding this in google. But couldn't find much help.
I'm new to google test and resharper. So any help would be greatly appreciated.
Thanks in advance.
No, I'm afraid ReSharper cannot do that out of the box.
Though it is quite powerful, so if you manage to write a script that does the VM specific part, ReSharper should be able to cope with it. What that script needs to do is:
It must be run on the host (Windows).
Copy the test binary to the QNX system in the VM.
Execute the test.
Capture the test's output and redirect it to the host's stdout.
The ReSharper options can be set here:
Menu ReSharper > Options...
In the left pane scroll down to Tools > Unit Testing > C++ Tests
In the text field Command: you need to enter the path to the script.
See https://www.jetbrains.com/help/resharper/Reference_Options_Tools_Unit_Testing_CPP_Tests.html for more details.
I think you'll find that the msg box showing "ReSharper Ultimate – Error while running unit tests: Invalid path" has been caused by the last update to VS 2017, which has broken things. I usually run my google tests through resharper c++, and until a few days ago, it worked. Now, I see this exact same error.

NCover not finding unit tests

I am trying to install NCover in an existing C# .NET project for work. Unfortunately, after I download NCover and installed the Visual Studio extension, it wasn't finding any of the unit tests. The answers I've seen/heard seem to be in the vain of 'It wasn't working...time passed...it started working.'
I can run the tests with Visual Studio's Test Explorer, but I need to get NCover installed to see the code coverage. I had NCover installed previously, and other people on my team are getting it to work within the same project.
I am using Visual Studio 2013 with the newest version of NCover Desktop (v 5.1).
I am getting two errors in the console log.
The first switches between saying:
Agent Error (v4x64): An error occurred while loading assembly
and
Agent Error (v4x64): There was a problem loading test assembly [test path]. Could not get bytes from loader AppDomain
The second (after I try to run NCover) says it 'Could not load config' for the test dll.
I copied the 4 XML config file (Bolt.ext.config, Bolt.Extension2008.dll.config, NCover.exe.config, ncover.axplorer.exe.config) from one of my team members, so I'm pretty sure that I have my config correct.
Has anyone else experience this/have any suggestions? Help would be greatly appreciated!
Further information:
When I hover over the grayed out test dll in the bolt test panel, I get the following error:
Assembly is not loaded. Select and run to build and load this assembly
I was looking at this post, but it doesn't seem like any of the solutions are working for me...
After working with some of the other developers in my office, we discovered the issue was with the NCover version. For our tests to run, we needed to use NCover v5.0. Neither v5.1 or v5.2 would work with our setup. Not sure what changed in v5.1 that wouldn't let it find the tests, but I'm glad it's working now :)

Throwin std::exception causes VS 2013 unit testing module crash

I've created unit test project for my C++ application in Visual Studio 2013. Unfortunately, it does not correctly handles exceptions during test: If i run test that just does following:
throw std::runtime_exception("hello!");
I see Windows "application has stopped working" box telling me that vstest.executionengine.exe has crashed. Meanwhile, Test Explorer in visual studio shows that this test has passed without errors.
Visual studio itself reports that "active test" was aborted, and error is unexpected. Reffers to https://msdn.microsoft.com/en-us/library/bb787181(VS.85).aspx but there is absolutely no useful information on that page about my problem.
How to properly terminate test execution in C++?
Solution
Ensure that all your tests can run at one time, because that's how unit tests work in VS2013 (Run All i mean)
Ensure that you have no assert(..) calls, use Assert class provided by header CppUnitTestAssert.h
Try removing I/O from your test code, for example, try using Logger class provided by header CppUnitTestLogger.h instead of your own implementation
Use command TESTS > Debug > Debug all tests to run all tests in debug mode, you will definetely find reason of your crashes.
More information
Reason of crashes
I think it is how assertion worked in my code, maybe it's abort(). This caused something unexpected in hosting process.

Visual Studio 2015 or 2017 does not discover unit tests

EDIT 2016-10-19:
The original question was about an issue specific to VS2015 CTP6 with the XUnit test runner. It's clear from the answers that there is a much broader issue with unit test discovery in Visual Studio which may occur in many different situations. I have cleaned up my question to reflect that.
I have also included a script in my own answer that I still use to this day to solve similar problems when they appear.
Many other answers have also proven helpful in better understanding the intricacies of the VS test runner. I appreciate that people are still sharing their solutions!
Original question 2015-04-10:
Since yesterday, my Visual Studio Test Explorer won't discover tests for any of my projects. It does not show the green loading bar after building, either.
When I go to the Visual Studio Test Explorer and click "Run All", or when I right-click any test method and select "Run Tests", I get the following in my output window:
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.
I am running Visual Studio 2015 CTP 6 on Windows 10 Pro Technical Preview, build 10041. The .NET Framework version does not seem to matter - it happens on 4.0, 4.5.2 and 4.6.
I tried with the following testing frameworks and all of them give the same behavior:
Microsoft.VisualStudio.QualityTools.UnitTestFramework v14.0.22609.0
xunit v2.1.0-beta1-build2945 with xunit.runner.visualstudio v2.1.0-beta1-build1051
NUnit v2.6.4 with NUnitTestAdapter v2.0.0
I found an issue on GitHub (xunit) that appeared to be similar: Cannot get tests discovered #295, with this comment from the xunit team:
Be aware that Visual Studio 2015 CTP 5 has been reported to be broken
by many people with unit testing in general (not just xUnit.net), so
don't expect that to work.
Also, please make sure you've cleaned out Visual Studio's runner
cache. If it gets corrupted, Visual Studio will permanently misbehave
until it's deleted. To clear the cache, shut down all instances of
Visual Studio, then delete the folder
%TEMP%\VisualStudioTestExplorerExtensions (honestly, it probably
wouldn't hurt to delete everything in %TEMP% that can be deleted).
I tried their suggestion to delete the folder %TEMP%\VisualStudioTestExplorerExtensions. Unfortunately that did not fix the problem.
I noticed that ReSharper actually is able to discover some tests. It only works for the VS and NUnit tests, not for xunit.
There has to be some sort of temp or cache folder I need to clear, but I know Visual Studio has many of them and not all of them can be deleted without unwanted side-effects.
To my surprise, clearing temp files located in the %TEMP% directory resolved the issue for me.
Note: This path is generally at C:\Users\(yourusername)\AppData\Local\Temp
As #Warren-P included, you can navigate to the temp folder by putting in %temp% in Start Menu, or launch "File Explorer" and enter %temp% in the address bar.
It could be that your code is compiled with x64 therefore have to enable the Default Processor Architecture as X64.
Test > Test Settings > Default Processor Architecture > X64
Check out, if NUnit Test Adapter 2/3 is installed in VisualStudio.
(Tools>Extensions and Updates )
Make sure that correct processor architecture is chosen:
(Test>Test Settings>Default Processor Architecture)
EDIT 2016-10-19 (PowerShell script)
This issue still returns every now and then. I wrote a small PowerShell snippet to automate clearing the relevant cache/temp folder/files for me. I'm sharing it here for future readers:
#(
"$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 }
Make sure to close Visual Studio beforehand and it's probably a good idea to reboot afterwards.
Deleting the TEMP folder may not be necessary and may in some cases even be undesirable, so I would recommend trying without clearing the TEMP folder first. Just omit the "$env:TEMP".
Original answer 2015-04-12
The problem was "solved" after a thorough cleaning of Visual Studio-related temp/cache folders.
Since I did not have the time to go through everything one-by-one and then test in-between, I unfortunately don't know which one actually caused the problem.
These are the exact steps I've taken:
Closed Visual Studio
Used CCleaner to clear system and browser temp files/folders
Manually cleared/deleted the following files/folders:
%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.
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.
The solution in my case was just to install the NUnit 3 Test Adapter extension to my Visual Studio 2015.
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.
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.
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!
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.
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
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
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.
I had the same problem. I just cleaned and rebuilt the project and I was able to see the tests that were missing.
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\SpecificFold‌​erCache.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
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 solved this problem by realizing that the Target Framework for my test project was different than the project under test. Yes, I caused this problem by changing the target framework from the default (Project>Properties>Application), but failed to this this for the test project, which was created several weeks later. The mismatch did not cause a compiler error, but it did result in a warning in the Error List window. Once I selected the option to display warnings, the solution was obvious.

Visual Studio 2012 Unit Tests not running remotly because of NuGet error

I am running VS 2012 (Version 11.0.61030.00 Update 4). I created a project to run unit tests which had been working 100%. I have 2 test settings profiles. One for running tests local (still works fine) and another for running test remotely (using a test controller and test agents). All tests worked back in Feb. 2014. I have not run them until today. I receive the following error in the Visual Studio output window for tests:
Cannot discover test extensions installed by NuGet. The NuGet service is not
available. Tests may not be found due to missing test adapter extensions. The
connection to the controller was lost.
As far as I know I never configured NuGet in the first place. At this point, I don't really want to use it until I thoroughly research the technology. It is quite possible I updated the Visual Studio software between Feb and now, but I don't think so. Why do I have a sudden dependecy on NuGet?
What can I do to fix this? I suppose this could be a bogus message and my real problem is something else entirely, but hopefully someone else has seen this.
NOTE: connection is not an issue. I have a solid drive mapping from VS2012 machine to Test Controller. Tests do not deploy to controller or to test agent machines. Problem is not limited to Unit Test project. I have a CUITest project with the same issue, but let's stick to unit test project for this post.
thanks
The message I was seeing referring to NuGet had nothing to do with my issue. Yes, I would see this message during test execution, but I'm also seeing it during builds. The message was likely always there I just failed to notice it. My problem was actually tied to something else and since I could ignore the Nuget message, I focused more on the "connection to the controller was lost" message.
So now my issue: As stated I had a solid connection from VS2012 to the controller. However, you also need a connection from the controller back to the VS2012 machine. There was a connectivity issue in that direction due to my DHCP address changing (lease expired). So there was no code issue. It was an environment issue. The NuGet error was just a distracting waste of time.