本文介绍了已安装 GoogleTest 后如何在 Visual Studio 2017 中配置 GoogleMock?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn 包安装到我的 VS 2017 应用程序解决方案中.这是通过添加新项目/其他语言/C++/Test/Google 测试"向我的解决方案添加一个新的 GoogleTest 项目来实现的.

测试运行良好,但现在我准备尝试使用 gmock 进行一些模拟.所以,我通过 NuGet 安装了 googlemock.v140.windesktop.static.rt-dyn,但我不知道如何将它集成到我的测试项目中.

我的 packages.config 如下所示:

<?xml version="1.0" encoding="utf-8"?><包><package id="googlemock.v140.windesktop.static.rt-dyn" version="1.7.0.1" targetFramework="native"/><package id="Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn" version="1.8.0" targetFramework="native"/></包>

...但据我所知,没有外部依赖项头文件或 .lib 文件可以链接到.我不知道从这里去哪里.:-)

附:我已经在 Microsoft 的 C++ 论坛上发布了有关 GoogleTest 的问题,但即使 GoogleTest 是通过 Visual Studio 安装的,他们也不会回答这些类型的问题.

解决方案

NuGet 上有一些糟糕的 Google Test/Google Mock 包可用,例如这个问题引用的那个.您想要的是 gmock 包 由 Google Inc (版本 v1.8.1 至此写作).

安装此包后,您项目的 packages.config 应如下所示:

<?xml version="1.0" encoding="utf-8"?><包><package id="gmock" version="1.8.1" targetFramework="native"/></包>

您只需添加即可开始使用 GMock

#include "gmockgmock.h"

文档中所述.p>

I installed the Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn package into my VS 2017 application solution. This was accomplished by adding a new GoogleTest project to my solution via "Add New Project/Other Languages/C++/Test/Google Test".

The testing works well, but now I am ready to try some mocking with gmock. So, I installed googlemock.v140.windesktop.static.rt-dyn via NuGet, but I have no idea of how to get it integrated into my test project.

My packages.config looks like this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="googlemock.v140.windesktop.static.rt-dyn" version="1.7.0.1"  targetFramework="native" />
  <package id="Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn" version="1.8.0" targetFramework="native" />
</packages>

... but there are no external dependency header files or .lib files to link to as far as I can see. I don't know where to go from here. :-)

P.S. I have posted questions about GoogleTest on Microsoft's C++ forum, but they will not answer these types of questions about GoogleTest even though it was installed via Visual Studio.

解决方案

There are some bad Google Test / Google Mock packages available on NuGet, such as the one referenced by this question. The one you want is the gmock package authored by Google Inc (version v1.8.1 as of this writing).

Once this package has been installed, your project's packages.config should look like:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="gmock" version="1.8.1" targetFramework="native" />
</packages>

And you can begin using GMock simply by adding

#include "gmockgmock.h"

as mentioned in the documentation.

这篇关于已安装 GoogleTest 后如何在 Visual Studio 2017 中配置 GoogleMock?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-13 13:17