"Exception occurred while test discoverer was loading tests" - c++

I'm writing a desktop Windows 8 application, and always get this error when building the project:
An exception occurred while test discoverer 'MSAppContainerTestDiscoverer' was loading tests. Exception: Object reference not set to an instance of an object.
I'm using the C++ unit test framework that's built into Visual Studio 2012, and the error doesn't seem to impact my builds or test runs. I haven't found anything about this online; any ideas what causes this error?

Post a build, it seems VS triggers all installed test-adapters (MSTest, et.all) into a discovery phase where they attempt to refresh the list of tests. If during this process, an exception occurs, the above generic error message is shown.
I faced this with NUnit - but you seem to be having the same with MSAppContainer. I'm not sure what that is. It won't affect your builds but may cause tests to be not found.
The NUnit adapter has been modified to log detailed information to the Output window (Tests) in case of a failure. For MSTest, I think this link should help uncover more details

Related

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.

Windows Phone 8 Unit Test App FileNotFoundException

I have a Windows Phone 8 app that I'm trying to unit test. I added a Windows Phone Unit Test App to my project and added a reference to my Windows Phone project. When I try to debug a test in the emulator or my device, I get a FileNotFoundException. It errors in the unit test's MainPage.xaml.cs when it tries to instantiate a TestExecutorServiceWrapper.
It seems like I'm missing some references, but I can't figure out what I'm missing.
Exception Message:
The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Exception:
{System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)
at vstest_executionengine_platformbridge.MessageTransmitter..ctor()
at Microsoft.VisualStudio.TestPlatform.TestExecutor.TestExecutorServiceWrapper..ctor()
at WinPhoneApp.UnitTests.MainPage..ctor()}
Stack Trace:
at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)
at vstest_executionengine_platformbridge.MessageTransmitter..ctor()
at Microsoft.VisualStudio.TestPlatform.TestExecutor.TestExecutorServiceWrapper..ctor()
at WinPhoneApp.UnitTests.MainPage..ctor()
I ran into this problem as well. I found some good info here: http://dotnetbyexample.blogspot.com/2013/06/x86arm-configuration-gotcha-in-windows.html
Short story: The Windows Phone 8 Unit Test app project is a platform specific project (x86 for the emulator, ARM for the actual device). My WP8 project was AnyCPU, so when I added the test project I tried to make the test project AnyCPU to match my main settings and that resulted in this error.
Adding a config for testing the phone project (as suggested by the blog post linked) solved my problem and my tests now run fine.
So I didn't find out what was the issue with my test project, but I did get it working. I ended up adding a new Unit Test app to my project. I ran the default unit test that is added to a unit test project. It ran fine and there were no FileNotFoundException. So I started adding all my references, including the NuGet references, checking that the unit test ran on each change. Then one by one, I started adding each of the classes in my old unit test app to the new unit test app, and testing the default unit test with each change. After adding all the classes to the new testing project, I didn't get any errors.
So the bad news is I don't know what caused the initial error, but at least I got my new unit test project working.

How to generate custom build errors in Visual Studio 10

I'm trying to integrate a custom c++ unit test framework into my build process, and would like the unit tests to run as a final step in the build. Presently I'm executing the unit test in a post-build execution of a batch file, which outputs the test results to the console. If any test fails, the post build step exits with status 1.
This produces a build error in the Error List pane, as desired, but I'm looking for a way to customize the error message content to show that some unit tests failed.
Is that possible?
Yes, in fact this is the method used by the Boost.Test library.
I'm not sure of the exact format requirements but output like:
c:\path\to\file.cpp(line_number) : message
should get added to the error pane in the IDE.

Visual Studio 2010 UnitTestAdapter could not be loaded

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.