2

Adding a link dependency to zlibwapi.lib causes all of my unit tests to fail with the message "Failed to setup the execution context to run the test". Unfortunately, the message does not provide enough detail to troubleshoot the problem. It would be extremely useful to know specifically why the test execution context could not be setup, e.g., cannot load some.dll because of some_reason.

Other postings have noted that all the dependent libraries must be in the same directory, but this does not fix my problem. The dumpbin.exe tool clearly shows that adding a link dependency to zlibwapi.lib only adds zlibwapi.dll to the imports section. Also, zlibwapi.dll's import section contains only KERNEL32.dll and MSVCR110D.dll which were already present in the unit test library's import section. All non-standard dependent libraries are in the unit test runtime folder and it still fails.

The problem is reproducible by downloading zlib, building it in Visual Studio 2012 SP3, and adding a native unit test. Specifically:

  1. Download zlib128.zip from http://www.zlib.net.

  2. Follow these tips (http://bugbeebox.com/2012/12/29/building-static-zlib-v1-2-7-with-msvc-2012/) to build on Visual Studio 2012.

  3. Add a native unit test project named zlibunittest to ...\zlib-1.2.8\contrib\vstudio\vc11. In Build\Configuration Manager, add an x64 bit platform for the new project, verify it's Build checkbox is checked, and choose x64 for the active solution platform. It's also useful to add a project dependency from zlibunittest to zlibvc to ensure the correct build order.

  4. Modify unittest1.cpp's TestMethod1 to appear as:

    TEST_METHOD(TestMethod1)
    {
        Assert::AreEqual(0, 0);
    }
    

    Set Test --> Test Settings --> Default Processor Achitecture to x64 and verify it runs correctly in test explorer.

  5. Modify zlibunittest Configuration Properties as follows:

    a) Add ..\..\..\..\; to C/C++ --> General --> Additional Include Directories so zlib.h can be found. b) Add $(OutDir); to Linker --> General --> Additional Library Directories so zlibwapi.* can be found. c) Add zlibwapi.lib; to Linker --> Input --> Additional Dependencies. d) Add copy ..\x64\ZlibDllDebug\zlibwapi.* $(OutDir) to Build Events --> Pre-Build Event so that the zlib runtime libraries will be in the same directory as the unit test library binaries.

  6. Modify unittest1.cpp's TestMethod1 to appear as:

    TEST_METHOD(TestMethod1)
    {
        Assert::AreEqual(0, 0);
        gzopen(NULL, NULL);
    }
    

    The NULL args to gzopen are not relevant to this error because it never gets that far.

  7. Run the unit test in Test Explorer and get the generic error "Failed to setup the execution context to run the test".

  8. Now, comment out the gzopen call in TestMethod1 and remove zlibwapi.lib from the additional linker dependencies and watch the error disappear.

Does anyone know how to make ZLib work with Visual Studio 2012 Native Unit Tests?

At the very least, does anyone know how to get more detail on this particular error, i.e., a unit test runtime log somewhere?

user2319854
  • 33
  • 1
  • 5

1 Answers1

0

It turns out that zlib had a bug which caused it to require the Windows 8 runtime. So apparently running the unit tests on my Windows 7 development machine caused the mysterious and unnecessarily cryptic "Failed to setup execution context" error.

Once I applied this fix https://stackoverflow.com/a/17113126/2319854 to zlib and rebuilt all, the unit tests started working again.

Community
  • 1
  • 1
user2319854
  • 33
  • 1
  • 5