I have a project which is still being developed.
我有一个仍在开发的项目。
I want to make unit tests in another project but i couldn't manage to use the existing source files.
我想在另一个项目中进行单元测试,但我无法使用现有的源文件。
Say that, i have header1 and source1 in actual project. I want to include hedaer1, source1 and testSource1 files in the test project. And whenever i update the code in header1 or source1 in the actual project, it must be updated automatically in the test project.
说,我在实际项目中有header1和source1。我想在测试项目中包含hedaer1,source1和testSource1文件。每当我更新实际项目中header1或source1中的代码时,它必须在测试项目中自动更新。
I can include the headers in test project, but can not compile. Seems like i have to link static or dinamically in the test project. Is there any solution ? By the way, i'm using Boost test framework, if it matters.
我可以在测试项目中包含标题,但无法编译。好像我必须在测试项目中链接静态或dinamically。有什么解决方案吗?顺便说一下,我正在使用Boost测试框架,如果重要的话。
1 个解决方案
#1
1
I had the same problem with GTest framework (but I think it does not matter). So I found 2 possible solutions:
我对GTest框架有同样的问题(但我觉得没关系)。所以我发现了两种可能的解决方
- Change output type of the tested project.
- 更改测试项目的输出类型。
Make tested project output as "static library" ( Project - Properties - Configuration Properties - Configuration Type - Static Library (.lib) ), then add the library file to the testing project (Project - Properties - Linker - Input - Additional Dependencies - Path to lib file from tested project) there is article to read http://leefrancis.org/2010/11/17/google-test-gtest-setup-with-microsoft-visual-studio-2008-c/
将测试的项目输出作为“静态库”(项目 - 属性 - 配置属性 - 配置类型 - 静态库(.lib)),然后将库文件添加到测试项目(项目 - 属性 - 链接器 - 输入 - 附加依赖项 - 路径来自测试项目的lib文件)有文章可以阅读http://leefrancis.org/2010/11/17/google-test-gtest-setup-with-microsoft-visual-studio-2008-c/
OR
要么
- Add files from tested project to testing project through menu Project - Add Existing Item (choose *.h and *.cpp files you need).
- 通过菜单Project - Add Existing Item(选择* .h和* .cpp文件)将测试项目中的文件添加到测试项目中。
If someone has more convenient solution to the problem it would be great to know it.
如果有人能够更方便地解决问题,那么了解它会很棒。
#1
1
I had the same problem with GTest framework (but I think it does not matter). So I found 2 possible solutions:
我对GTest框架有同样的问题(但我觉得没关系)。所以我发现了两种可能的解决方
- Change output type of the tested project.
- 更改测试项目的输出类型。
Make tested project output as "static library" ( Project - Properties - Configuration Properties - Configuration Type - Static Library (.lib) ), then add the library file to the testing project (Project - Properties - Linker - Input - Additional Dependencies - Path to lib file from tested project) there is article to read http://leefrancis.org/2010/11/17/google-test-gtest-setup-with-microsoft-visual-studio-2008-c/
将测试的项目输出作为“静态库”(项目 - 属性 - 配置属性 - 配置类型 - 静态库(.lib)),然后将库文件添加到测试项目(项目 - 属性 - 链接器 - 输入 - 附加依赖项 - 路径来自测试项目的lib文件)有文章可以阅读http://leefrancis.org/2010/11/17/google-test-gtest-setup-with-microsoft-visual-studio-2008-c/
OR
要么
- Add files from tested project to testing project through menu Project - Add Existing Item (choose *.h and *.cpp files you need).
- 通过菜单Project - Add Existing Item(选择* .h和* .cpp文件)将测试项目中的文件添加到测试项目中。
If someone has more convenient solution to the problem it would be great to know it.
如果有人能够更方便地解决问题,那么了解它会很棒。