Search code examples
c++qtgoogletestgooglemock

Config gmock in QT


It's the first time I make mock object in QT. I'm trying using Gmock, but I don't know how to using it. Now, I create project TestGmock (QT Application) in QT, and I copy include folder in gmock-1.7.0 ( download it from https://code.google.com/) to TestGmock project directory ( and the same with gtest ). In class main :

#include <QCoreApplication>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
int main(int argc, char *argv[])
{
    testing::InitGoogleMock (&argc, argv);
    return RUN_ALL_TESTS();
}

But error :

  • C:\Qt\Qt5.2.1\Tools\QtCreator\bin\TestGmock\main.cpp:6: error: undefined reference to `testing::InitGoogleMock(int*, char**)'
  • C:\Qt\Qt5.2.1\Tools\QtCreator\bin\TestGmock\gtest\gtest.h:2288: error:undefined reference to `testing::UnitTest::GetInstance()'
  • C:\Qt\Qt5.2.1\Tools\QtCreator\bin\TestGmock\gtest\gtest.h:2288: error:undefined reference to `testing::UnitTest::Run()' collect2.exe:-1:
  • error: error: ld returned 1 exit status

Please help me using gmock and gtest in QT.


Solution

  • This error is caused the fact, that Qt Creator couldn't find Gmock library. There is no need to put it in your project (or Qt installation) directory, but you should add INCLUDEPATH and LIBS options in .pro file. Look at Adding external library into Qt Creator project.