Linking google test to your main project

霸气de小男生 提交于 2020-01-04 05:47:11

问题


I am new to the gtest. I have followed a tutorial how to set it up in the VS 2105. But all that I could find talked about how to build and link gtest. I am passed that level. The code below runs and passes the first dummy test.

#include "gtest/gtest.h"

TEST(VI, simple) {
    EXPECT_EQ(false, false);
}

int main(int argc, char* argv[]) {
    testing::InitGoogleTest(&argc, argv);
    RUN_ALL_TESTS();
    std::cin.get();
    return 0;
}

My question: How do I exactly hook it up to my project that I want to test? Both gtest project and my "code" project are in the same solution. As far as I understood from reading numerous tutorials, I need 2 things:

1) to include my .h of the class I am about to test (easy and done)

2) To compile my "code" project into a static lib and then hook up the lib to gtest project so I can create and test objects from the "code" project.

I am struggling with the point 2. How exactly do I go about it?

Thank you for help in advance.


回答1:


  1. Add a new empty Win32 project to your solution, in its properties select Project Type "static library (.lib)"

  2. Move all your sources except the main() function to that project

  3. Add a reference to the .lib project to both your main application project and the google test project



来源:https://stackoverflow.com/questions/42259074/linking-google-test-to-your-main-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!