Unit Testing issue in Visual Studio 2012

2019-01-23 03:42发布

Whenever I try to run any of the test from my test suite in Visual Studio 2012 I get

Test Failed - [test method name]

Message: Failed to set up the execution context to run the test

and my test is not even started (i.e. the source of the test failure is pointing at the beginning of the test method:

here--> TEST_METHOD([test method name]) {

}

What does this message mean, what could be the cause for it to appear and what should I do for my test to run correctly?

7条回答
Emotional °昔
2楼-- · 2019-01-23 03:54

I was also getting this error only in the Release configuration, because I accidentally used a debug lib as one of the library dependencies of my test project. ( same problem as bmann's post )

To find which library was causing the problem, I commented out all the test code and its includes, added one empty test, and removed my dependency libraies one by one until the test worked.

查看更多
聊天终结者
3楼-- · 2019-01-23 03:55

After some more research I realized that I overlooked the fact that I changed the 'Output Directory' of the project containing the methods under test (which was a .dll) and was not in the same folder as my test project library, hence giving me the message:

Message: Failed to set up the execution context to run the test

So the problem was solved by making sure that the .dll containing the methods under test was in the same folder as my test project library so that at run-time my test project could find the .dll.

查看更多
做自己的国王
4楼-- · 2019-01-23 03:55

I was getting this error, and it was because I was using a debug DLL, and did not have debug c++ runtimes where they could be found. I copied the debug c++ runtimes into the same directory and the issue was resolved.

查看更多
唯我独甜
5楼-- · 2019-01-23 04:03

I had the same issue and the previously mentioned suggestions did not fix it for me. My project uses some third party libraries and the paths to these are set up correctly in the compiler and linker settings of my VS project.

It turns out that the VS test engine was unable to find the libraries, so I added the paths to these libraries to the PATH environment variable. This fixed the issue for me.

Tip: Try running the unit tests from the command line using VSTest.Console.exe. The error messages helped me debug my issue more easily.

查看更多
时光不老,我们不散
6楼-- · 2019-01-23 04:08

For those searching for other answers, this turned out to be a problem finding all the DLLs needed. I followed the advice above getting both the test dll and the dll to be test in the same location but still got this error.

My test DLL, out of its native environment, couldn't find its children DLL. You can figure out what is missing by running depends.exe . Adding the locations to these other DLL's to my path resolved the problem and everything now works.

查看更多
手持菜刀,她持情操
7楼-- · 2019-01-23 04:15

I had this error after including a third party dll (OpenCV) in my project. Adding the dll to path or dropping it in the system32 directory does work, but I have a better solution.

The test is run from a directory called AppX. In my case it is here: .......OneDrive\Documents\Visual Studio\Projects\TutorialOcr\x64\Debug\OcrTesting\AppX

I just dropped the dll in there and the test worked!

查看更多
登录 后发表回答