将Google测试链接到您的主项目 [英] Linking google test to your main project

查看:78
本文介绍了将Google测试链接到您的主项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是gtest的新手.我遵循了有关如何在VS 2105中进行设置的教程. 但是,我所能找到的所有内容都是关于如何构建和链接gtest的. 我达到了这个水平.下面的代码运行并通过了第一个虚拟测试.

I am new to the gtest. I have followed a tutorial how to set it up in the VS 2105. But all that I could find talked about how to build and link gtest. I am passed that level. The code below runs and passes the first dummy test.

#include "gtest/gtest.h"

TEST(VI, simple) {
    EXPECT_EQ(false, false);
}

int main(int argc, char* argv[]) {
    testing::InitGoogleTest(&argc, argv);
    RUN_ALL_TESTS();
    std::cin.get();
    return 0;
}

我的问题: 如何准确地将其连接到要测试的项目? gtest项目和我的代码"项目都在同一解决方案中. 据我阅读大量教程了解,我需要做两件事:

My question: How do I exactly hook it up to my project that I want to test? Both gtest project and my "code" project are in the same solution. As far as I understood from reading numerous tutorials, I need 2 things:

1)包括我要测试的班级中的.h(简单易做)

1) to include my .h of the class I am about to test (easy and done)

2)将我的代码"项目编译为静态库,然后进行连接 lib到gtest项目,这样我就可以从中创建和测试对象 代码"项目.

2) To compile my "code" project into a static lib and then hook up the lib to gtest project so I can create and test objects from the "code" project.

我正在努力解决第二点.我到底要怎么做?

I am struggling with the point 2. How exactly do I go about it?

谢谢您的帮助.

推荐答案

  1. 向您的解决方案中添加一个新的空Win32项目,在其属性中选择项目类型"静态库(.lib)"

  1. Add a new empty Win32 project to your solution, in its properties select Project Type "static library (.lib)"

将除main()函数以外的所有源代码移至该项目

Move all your sources except the main() function to that project

将对.lib项目的引用添加到您的主应用程序项目和google测试项目中

Add a reference to the .lib project to both your main application project and the google test project

这篇关于将Google测试链接到您的主项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆