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.
Related
I've fixed a null reference problem. Now when I run the test related to that class, it fails. I'd like to know whether is possible to run a test in debug mode so I'll know why I am getting the exception?
The test was written by some else, it's calling a method, as part of the setup, with a lot of logic in it. I'd like to step in to see how values are being returned.
Thank for helping.
It is indeed possible, using the NUnit Test Adapter for Visual Studio 2012.
Also, just so you're aware: failed assertions will throw exceptions, causing the debugger to break execution. You can adjust your configuration to work around this, as described in this thread:
Debugging in VS2012 with NUnit without throwing exceptions?
You can also use ReSharper, which makes it pretty easy. Or, you can just go into the properties for your DLL project that has the test in it and make the test runner you are using the exe that runs when you run the project.
Right click the project in the solution explorer, select "Properties" from the menu, go to the "Debug" tab, click the "Start external program" radio button then set the project as the active project and run in debug mode.
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
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.
I am trying to run my unit tests (Test->Debug->Tests in current solution) in VS 2010.
The solution is built in Release mode. When I try to do that, VS is crashing.
Do you have any ideas?
Cheers
I guess the problem lies with the test code. Test code is crashing and bringing down the VS IDE too.
See while debugging, the tests are run in-proc and therefore because of any exception in test code the VS would crash too.
I would suggest that you set the "Break on Common language runtime exceptions" (Goto Debug -> Exceptions menu), and then debug the tests. That way you could hunt the exception in your test code.
I've just started using resharper and I found a very annoying thing about it. When debugging a unit test, I try to step-into (F11) a method, but visual studio complains that source code is not available. The problem is that resharper is wrapping method calls with its own classes. Of course I can put a braeakpoint further in my source, but this is very annoying. Do you know if thereĀ“s a solution for this? By the way, I'm using NUnit to write my tests
Thanks
Federico
After some playing around I managed to recreate this on my setup (Xunit.net in resharper, visual studio 2008)... The steps I took to recreate this are:
Set the dll that contains the tests as the startup project (I know you don't need to do this, was just trying to get it to fail)
Put a breakpoint in the unit test
Push F11 (the shortcut key for 'step into' in my configuration)
This complains 'Cannot start test project 'RowanBeach.Crm.Domain.Test' because the project does not contain any tests.'
Run the 'Debug Unit Tests' command from the Resharper menu (I have this bound to a key combination on my machine)
This displays the 'No source code available...' message
Of course that's not how you should start unit tests from resharper! :) If that's what you were doing (or something similar), try this instead:
Don't bother setting the dll as the startup project - it doesn't need to be
build or rebuild the dll that contains the tests
set the breakpoint
Put the cursor somewhere in the source code for the unit test you want to debug to set it as the 'current context' unit test
Run the 'Debug Unit Tests' command from the Resharper menu (You might want to bind this to a key combination if you haven't already)
Hopefully, that should work
What type of tests are you running - NUnit? MS Test? Something else?
I've never found it difficult to debug tests using R# - just put a breakpoint in your test and go. What method are you trying to step into? I've generally not tried to step into the NUnit methods themselves (assertions etc) but stepping into your own code should be okay.
If you can come up with a quick example, I'd be happy to try it myself.