Linking google test to your main project

2019-07-09 05:18发布

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条回答
The star\"
2楼-- · 2019-07-09 06:13
  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

查看更多
登录 后发表回答