2

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.

Illia
  • 301
  • 1
  • 4
  • 16

1 Answers1

3
  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

rustyx
  • 80,671
  • 25
  • 200
  • 267
  • Is there particular reason for the new project to be WIn32 and not 64 or it does not matter? I compiled both gtest and my project in x64. – Illia Feb 15 '17 at 21:37
  • Win32 is the type of the project template in the New Project dialog. – rustyx Feb 15 '17 at 21:55
  • I see. Is there a way to turn my current "code" project into a static lib and then create a new project just for a main? It seems easier and then coping all my files. Also my current project is a qt5 template project will that still work with it? – Illia Feb 15 '17 at 22:39
  • If you do that you will lose linker settings because a static lib project has librarian settings instead of linker settings. But can be done of course. – rustyx Feb 16 '17 at 07:18