googletest:如何设置? [英] googletest: how to setup?

查看:133
本文介绍了googletest:如何设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Linux机器。
我从此处下载了googletest包

I am using Linux machine. I have download the googletest package from here

但是,没有安装指南或其他关于如何正确设置的博客
README文件不好,我不明白什么

However, there is no installation guide or other blogs related on how to set it up properly The README file is no good that I can't understand what it is talking about?

任何人都可以提供一个简单的例子来说明如何使用gtest包测试.cc文件中的简单函数?

Can anyone provide a simple example on how to test a simple function inside a .cc file with that gtest package?

推荐答案

这是我做的,你可以根据需要进行调整。我将我的Linux机器上的gtest-1.6.0.zip(从版本页面)下载到〜 /下载完全输入/ home / me / Downloads /

Here's what I did and you can adjust as necessary. I downloaded gtest-1.6.0.zip (from the releases page) on my Linux box into ~/Downloads which typed out fully is /home/me/Downloads/

将gtest-1.6.0.zip的内容解压到〜/ Downloads / gtest-1.6.0 /

Unzip the contents of gtest-1.6.0.zip into ~/Downloads/gtest-1.6.0/

cd /home/me/Downloads
unzip gtest-1.6.0.zip

构建gtest库,因为它需要include在测试可执行文件中。
编译对象文件gtest-all.o:

Build the gtest library because it's something you need to "include" in your test executable. Compile the object file gtest-all.o:

g++ -Igtest-1.6.0/include -Igtest-1.6.0 -c gtest-1.6.0/src/gtest-all.cc

库存档libgtest.a:

Then build the library archive libgtest.a:

ar -rv libgtest.a gtest-all.o

现在可以在〜/ Downloads下创建test.cc文件。下面是一个我用来确保编译的示例测试文件。

Now you can create your test.cc file in ~/Downloads. Here is an example test file that I used to make sure it compiles.

#include "gtest/gtest.h"

TEST(blahTest, blah1) {
    EXPECT_EQ(1, 1);
}

int main (int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);

    int returnValue;

    //Do whatever setup here you will need for your tests here
    //
    //

    returnValue =  RUN_ALL_TESTS();

    //Do Your teardown here if required
    //
    //

    return returnValue;
}

要编译自己的测试并运行它:

To compile your own test and run it:

g++ -I/home/me/Downloads/gtest-1.6.0/include -pthread test.cc libgtest.a -o test_executable

然后执行它:

./test_executable

根据需要进行修改。

这篇关于googletest:如何设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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