I have a Visual Studio 2012 C ++ solution generated using CMake in which I use the Google test for unit tests. This works mostly fine, but in one of my tests I want to read a settings file from a local directory. To find the file, I will copy the file as a post-build step from my source code to the build and installation directory using the following CMake commands:
install(FILES ./adapters/settingFile.txt DESTINATION .) add_custom_command(TARGET testAdapters POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/adapters/settingFile.txt" "${CMAKE_CURRENT_BINARY_DIR}" COMMENT "Copying elastix parameter files")
This works fine: after creating my test, the settingFile.txt file is in the same place as testAdapters.exe. By right-clicking on the testAdapters project and starting a debugging session, you can also find the find.
However, if I select a test from the Explorer window, either Run All, or by right-clicking the test and selecting Run Run Selected Tests, the test cannot find settingsFile.txt. By right-clicking and selecting "Debug selected tests", I found that running a test from "Testing" in the working directory defaults to the program directory for the visual studio: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE I can think of several possible solutions, but I donโt know how to do it:
- Set the working directory for Tag Explorer
- Set working directory for each test executable
- Set working directory for all Google tests
- Using the CMake Kit, determine what points to a user-specified location and use it in test code. (I find this a rather ugly solution)
I need a platform independent solution. Does anyone know how to achieve (1) or (2), or do you know the best solution?
source share