问题描述
我正在Windows 10上使用Visual Studio2017。我创建了一个新的Google测试项目来测试我的另一个项目。 #include "gtest/gtest.h"
不会给出编译错误,但是#include "gmock/gmock.h"
会给出编译错误!在外部依赖项文件夹的内部,我看到存在gtest.h,但没有gmock.h。因此,当我尝试包括模拟时,编译器会给我以下错误:“无法打开包含的文件:'gmock / gmock.h':没有此类文件或目录”。当我进入工具->扩展和更新时,我看到Google Test Test Adapter的版本为:0.10.1.7,其发行说明说它支持Google Test V1.8.0,该版本具有google模拟https://github.com/google/googletest/releases。
-
为什么gmock.h不存在?我需要更新“ Google Test的测试适配器”还是Google Test本身?是因为我可能有较低版本的Google测试吗?我什至不确定如何找到自己拥有的Google Test版本;它没有说。
-
我是否应该不使用测试适配器,而是尝试将自己最新版本的googletest配置为Visual Studio 2017?
-
让gmock与我的设置一起工作的最佳方法是什么?
解决方法
由于某些原因,Visual Studio 2017附带了Google Test,但没有附带Google Mock。
This question说明了如何将标准软件包更新为包含Google Mock的软件包。但是,这对我不起作用。
我通过下载Google Test(包括Google Mock)并自行构建解决了该问题。
然后,创建一个新的控制台应用程序项目(不是一个Google Test项目)。更改配置以包括Google Test包含目录并链接到Google Test库。对于Google Test 1.8.1和Debug配置:
- 将
kubectl -n istio-system patch service istio-ingressgateway -p "$(cat<<EOF metadata: name: istio-ingressgateway namespace: istio-system annotations: service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "arn:aws:acm:xx-xxxx-1:123456789:certificate/xxxx-xxx-xxxxxxxxxxx" service.beta.kubernetes.io/aws-load-balancer-backend-protocol: "tcp" service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "443" service.beta.kubernetes.io/aws-load-balancer-internal: "true" service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*" spec: type: LoadBalancer externalTrafficPolicy: Cluster selector: app: istio-ingressgateway istio: ingressgateway EOF )"
和$(GTEST_DIR)\googletest\include
添加到其他包含目录中; - 将
$(GTEST_DIR)\googlemock\include
,gtestd.lib
和gmockd.lib
添加到其他依赖项中; - 将
gmock_maind.lib
和$(GTEST_DIR)\googlemock\gtest\Debug
添加到其他库目录。
$(GTEST_DIR)\googlemock\Debug
是您构建Google Test的位置。将其替换为实际目录或设置环境变量。
如果您构建应用程序,则Visual Studios测试资源管理器应将其识别为Google Test应用程序。