Visual Studio 2012 中的单元测试问题
每当我尝试从 Visual Studio 2012 中的测试套件运行任何测试时,我都会得到
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:
这里-->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?
经过更多研究后,我意识到我忽略了一个事实,即我更改了包含被测方法的项目的输出目录"(这是一个 .dll) 并且与我的测试项目库不在同一个文件夹中,因此给了我消息:
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
因此,通过确保包含被测方法的 .dll 与我的测试项目库位于同一文件夹中,以便在运行时我的测试项目可以找到 .dll,问题得以解决.
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.