问题
I tried the first time to implement some unit component tests for an private project of mine. I watched some videos about that and then I tried a step by step guide, how to write tests correctly. My first steps are working fine, but when I try to implement a unit test project in my c++ project (splitted into two projects, one project creates a DLL and the other project used it) I get an error and I don't know what exactly is wrong, because the error message isn't really helpful.
First my code. This code works fine, without any issues:
TEST_METHOD(TestMethod1)
{
Assert::AreEqual(1, 1);
}
But when I add my include for using my classes written in the DLL project this test method showed above failed and I don't know why. The only message I get is this (it is in German, sorry for that, but I don't find a similar error message in the web written in English):
Testname : TestMethod1
Test FullName : TestUnit::UnitTest1::TestMethod1
Testquelle : ...\unittest1.cpp Zeile 12
Testergebnis : Fehler
Testdauer : 0:00:00
Ergebnis Meldung : Fehler beim Einrichten des Ausführungskontexts
zur Ausführung des Tests
(That means something like "Error while setting up the execution context for test execution")
So ... I googled a bit and I found some information about such errors and they say, maybe there is something linked wrong or the linker don't find the LIB/DLL, but I compared my dependencies and library references with my (working) project that uses the DLL and the dependencies and references are the same.
Now I'm a bit confused and I don't know how to fix that error. Does someone have an idea?
回答1:
At least, after hours and days of trying and searching for a solution, I solved the problem, but please don't ask me how. I read an article about similar problems HERE and I used THIS tool and it said there are some files my project doesn't find like "libpng16.lib" and "MICROSOFT.VISUALSTUDIO.TESTTOOLS.CPPUNITTESTFRAMEWORK.DLL". After removing my libpng16 reference (because I don't need it anymore) the project still doesn't work. After adding the cppunittestframework.lib to my project (reference) and adding the folder (I thought, this UnitTest folder of visual studio is linked by standard) the test running perfectly. After removing this two references again, the test also working. Don't know what happens and I cannot say what was the solution for the problem, but now my tests are working. Hopefully it will still work in future ...
来源:https://stackoverflow.com/questions/23985590/vs-2013-unit-test-not-working-error-while-setting-up-execution-context