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条回答
太酷不给撩
2楼-- · 2019-01-23 04:16

The .dll created for the tests is run from the folder where it is built to. In my case "x64\UnitTests\Tests.dll". The rest of my application is in "x64\Debug\App.exe" and "x64\Release\App.exe". My application depends on external dlls which are located in the root folder of the project, which is also the "Working Directory" specified for debug launch.

But the Test Explorer test launcher ignores that setting and always launches Tests.dll with working directory "x64\UnitTests", and then fails to find the dlls I depend on. Adding SetCurrentDirectory("..\\.."); in, say, the test class constructor does not fix the problem, because the dll cannot even be loaded into memory if the static dependencies are not found.

I solved it by just setting the "Output Directory" to "$(SolutionDir)" for the UnitTests configuration. This causes the Tests.dll to be created in the root folder.

查看更多
登录 后发表回答