概述

本文主要描述如何在vs环境下,搭建可执行的gmock(gtest)运行环境。

环境搭建

编译gmock(以VS2013为例)

  1. 选择Win32 Project,修改工程名
  2. 选择Static library,Additional options全部不勾选
  3. 拷贝gmock文件到工程路径下:
1
2
3
4
5
6
7
8
\-- gmock-1.7.0
    \-- include
        |-- gmock
    |-- src
    \-- gtest
        \-- include
            |-- gtest
        |-- src
  1. 将gmock-1.7.0/src/gmock-all.cc以及gmoc-1.7.0/gtest/src/gtest-all.cc添加进工程
  2. 设置工程属性(C/C++ -> General -> Additional Include Directory)
1
2
3
4
$(ROOT_PATH)/gmock-1.7.0
$(ROOT_PATH)/gmock-1.7.0/include
$(ROOT_PATH)/gmock-1.7.0/gtest
$(ROOT_PATH)/gmock-1.7.0/gtest/include
  1. 使用UltraEdit将gmock-1.7.0/src/gmock-matchers.cc由UTF-8转为ASCII
  2. 编译工程生成lib文件

创建测试工程

  1. 选择Win32 Console Application,修改工程名
  2. 选择Console Application,Additional options只勾选Empty project
  3. 将gmock-1.7.0/src/gmock_main.cc添加进工程(图省事)
  4. 设置工程属性
1
2
3
4
5
6
7
- C/C++ -> General -> Additional Include Directory
    + $(ROOT_PATH)/gmock-1.7.0/include
    + $(ROOT_PATH)/gmock-1.7.0/gtest/include
- Linker -> General -> Additional Library Directories
    + 添加gmock lib文件所在路径
- Linker -> Input -> Additional Dependencies
    + 添加gmoc lib文件(ex: gmock.lib)
  1. 右键Set As StartUp Project
  2. 运行工程,可见0测试控制台界面

Source file can be got from github