How to build google test and google mock lib and use them in VS console app?

88 Views Asked by At

How to create a google test based unit testing project that integrate latest gtest.lib and gmock.lib in a console application or empty project (don't want to use visual studio google test project template)

Tried using google test project template in visual studio. Downloaded source zip of google test from github.

1

There are 1 best solutions below

1
Minxin Yu - MSFT On

1 . Download the google test source zip and unzip.

2 . Use command

cmake . -Dgtest_force_shared_crt=ON 

Then

cmake --build .

It will generate the debug version libs with /MDd.

3 . Create a console app in Visual Studio.

Add header file folder directory in project's properties -> C++ -> General -> Additional Include Directories.

Add lib folder directory in project's properties -> Linker -> General -> Additional Library Directories.

Input used library name in Linker -> input -> Additional Dependencies. Such as

gtest.lib
gtest_main.lib

Remove int main(){}. Add sample:

#include "gtest/gtest.h"

TEST(TestCaseName, TestName) {
    EXPECT_EQ(1, 1);
    EXPECT_TRUE(true);
}