locked
Setting runtime environment for C++ native unit test? RRS feed

  • Question

  • I am trying to create a C++ native unit test in VS2013. The code that is being tested normally resides in a DLL and is called by a non-Metro desktop app. At launch time, the main app checks some preferences and makes adjustments to the Dll load paths for supporting DLLs that may not reside in the same folder as the main exe. This lets you set up where the supporting DLLs reside (e.g., test/debug DLLs, newer versions, final release versions).

    Is there a way to set this runtime environment information up for unit tests? There doesn't seem to be anything obvious in a .runsettings file. TEST_MODULE_INITIALIZE() seems to be too late in the test load process to configure this.

    My unit test is failing with a "Failed to set up the execution context to run the test" error, and I am guessing that it can't find the supporting DLLs.

    Is there any way to set this up other than hardcoding the Path environment variable before running unit tests?

    Thursday, October 29, 2015 1:03 AM

Answers

All replies

  • Hi kenk77,

    Which DLLs that you want to configure?

    There is an blog that may benefit you:

    # Writing Unit Tests in Visual Studio for Native C++

    http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, October 30, 2015 5:12 AM
  • Any DLL that is not in the target folder. For example, ProductionCode.dll and SomeUnitTest.dll are built into the same output folder, but SupportCode1.dll and SupportCode2.dll are in some other folder. If I copy all of the SupportCode*.dll into the output folder, my unit test runs. If I write the full path to SupportCode*.dll into my PATH environment variable, then my unit test runs.

    Instead of copying all of the SupportCode*.dll files into one folder, or hardcoding the PATH environment variable, I would like to have the path to SupportCode*.dll be more configurable (since the path may be different for each developer). For example, is there something in .runsettings that can be set in conjunction with VS macros like $(OutDir) so that the path can be set relative to the solution file? Or, is there an entry point in unit tests where I can call SetDllPath() (this is what my app is doing to set the path at runtime)?

    Friday, October 30, 2015 5:00 PM
  • Hi kenk77,

    Sorry for that I didn't find the direct way using the PATH environment variable for assembly references.

    But as far as I know, we could deploy files for tests in testsettings file, so maybe you could add the dll files as the deployment items, and then using a post-build task to copy the files into the build output directory. Of course, the real issue is that we would add the path in the deployment settings.

    https://msdn.microsoft.com/en-us/library/ms182475.aspx

    As far as I know, two ways for VC++ references:

    http://www.codeproject.com/Articles/85391/Microsoft-Visual-C-Static-and-Dynamic-Libraries

    One way is that add the dll as the static references directly, another way is to add it as the dynamic references, but we need to modify the project property settings for the second way.

    So it seems that the two ways are not the solution you want to get.

    One members said that we could edit the .xxproj file like this case:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/1d01684d-9132-4b15-b866-757a9470e98d/using-environment-variables-in-the-relativepath-of-an-assembly-reference?forum=vcgeneral

    Maybe you could get a better path for this issue.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, November 2, 2015 7:10 AM