Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use gmock with xcode?

I want to use gmock (Google Mock) as mocking framework for a C++ project in XCode. Therefore I have to compile gmock as gmock.framework. Unfortunately the project does not come with a dedicated XCode project (gtest has one included).

Creating a Framework project in XCode and building it fails with multiple errors (basically the include paths used in the headers seem to be incorrectly looked up).

So (and sorry for the general question) how to compile gmock as Framework to be able to use it in other XCode Projects?

like image 562
gorootde Avatar asked Oct 20 '22 22:10

gorootde


1 Answers

I was able to get GMock working in Xcode by following these steps:

  1. Download this repo somewhere on your machine:

https://github.com/macmade/gmock-xcode

  1. Open the included Xcode project, build all the targets by pressing the play button, then close the project.

  2. Add the GMock Xcode project to your Xcode project as a subproject (can drag the GoogleMock.xcodeproj file to the project browser from Finder).

  3. In your testing target under 'Build Phases', add the GoogleMock, gmock, and gtest frameworks under Target Dependencies:

enter image description here

  1. Add the following line to your test files to start using GMock:

    #include <GoogleMock/GoogleMock.h>
    
like image 139
stephenspann Avatar answered Nov 01 '22 15:11

stephenspann