如何在2012年在Linux上设置googletest? [英] How to setup googletest on Linux in the year 2012?

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

问题描述

我正在使用Linux机器. 我已经从此处

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

但是,没有有关如何正确设置的安装指南或其他博客. 自述文件不好,我听不懂它在说什么?

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(从版本页面)下载到〜完整输入的/downloads是/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库,因为您需要将其包含"在测试可执行文件中. 编译目标文件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

它应该运行正常.从那里进行必要的修改.

And it should run fine. Modify as necessary from there.

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

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