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

问题描述

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

测试效果很好,但是现在我准备尝试使用gmock进行一些模拟了.因此,我通过NuGet安装了googlemock.v140.windesktop.static.rt-dyn,但是我不知道如何将其集成到我的测试项目中.

我的packages.config看起来像这样:

<?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>

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

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

解决方案

NuGet上有一些错误的Google Test/Google Mock软件包,例如此问题引用的软件包.您需要的是 gmock软件包,该软件包由Google Inc.(从v1.8.1版开始)写作).

一旦安装了此软件包,您项目的packages.config应该如下所示:

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

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

#include "gmock\gmock.h"

文档中所述.. >

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 "gmock\gmock.h"

as mentioned in the documentation.

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

09-12 19:29