简体   繁体   English

在Ubuntu 12.04上设置Google Test以在Eclipse中运行C / C ++ Test Runner插件

[英]Setting Up Google Test to Run through C/C++ Test Runner Plug-In in Eclipse on Ubuntu 12.04

Here's what I've tried: 这是我尝试过的:

In project properties I have included libgtest_main.a and libgtest.a under the libaries tab. 在项目属性中,我在libaries选项卡下包含了libgtest_main.a和libgtest.a。

In run configurations under the C++ Unit tab, I have set C/C++ testing to Google Tests Runner. 在C ++ Unit选项卡下的运行配置中,我已将C / C ++测试设置为Google Tests Runner。

In run configs, under the main tab, the C/C++ application is set as the binary file that was created during the build of my project. 在运行配置中,在主选项卡下,C / C ++应用程序被设置为在项目构建期间创建的二进制文件。

I have created a test folder as part of my project and written my tests in there. 我已经创建了一个测试文件夹作为我项目的一部分,并在那里编写了我的测试。

This is my code: 这是我的代码:

#include "../src/agent.h"
#include "../src/agent.cpp"
#include "gtest/gtest.h"

TEST(AgentTest, voidConstructorWorksProperly) {
Agent testAgent = Agent();
ASSERT_EQ(0, testAgent.getBrain());
}


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

}

I'm getting a syntax error on on the TEST function and a "could not be resolved" on the InitGoogleTest and RUN_ALL_TESTS. 我在TEST函数上遇到语法错误,并且在InitGoogleTest和RUN_ALL_TESTS上出现“无法解析”。

Hope someone can help - I've been at this for hours and it seems like something simple I've missed. 希望有人可以提供帮助 - 我已经在这里工作了好几个小时,看起来很简单,我错过了。

I had a similar problem and solved it running this script 我遇到了类似的问题并解决了运行此脚本的问题

       ./scripts/fuse_gtest_files.py . /yourprojectdir/

it is present in where you installed the google test framework (ie /tmp/gtest-1.5.0) 它出现在你安装谷歌测试框架的地方(即/tmp/gtest-1.5.0)

I dont know if it is the best solution but it worked for me. 我不知道它是否是最好的解决方案,但它对我有用。

I have had similar problems lately. 我最近遇到过类似的问题。

First to get rid of syntax errors and "could not be resolved" problems I have changed preferences of C++ indexer in Eclipse- it helped just to change one of settings, hit Apply and then get back to original ones and then hit Ok. 首先摆脱语法错误和“无法解决”问题我已经改变了Eclipse中C ++索引器的首选项 - 它只是更改了一个设置,点击Apply然后返回到原始设置然后点击确定。

Next, in case of running tests inside eclipse. 接下来,如果在eclipse中运行测试。 Please note that you need to set your run configuration to binary file with main function which runs tests (one presented by you). 请注意,您需要将运行配置设置为具有运行测试的main函数的二进制文件(由您提供)。 Probably if you made tests part of your other project which already has entry point and then you have set it's binary there not the test one. 可能如果您将测试作为已经具有入口点的其他项目的一部分,然后您已将其设置为二进制,那么就不会进行测试。 As you couldn't build project with two main functions there some filtering of source files has to be done to have independent build configuration for your main app and the other one for tests. 由于您无法使用两个主要功能构建项目,因此必须对源文件进行一些过滤,以便为主应用程序提供独立的构建配置,而另一个用于测试。 Unfortunately I have done this yet. 不幸的是我已经做到了。

This blog posts could be helpful for you: 这篇博文可能对您有所帮助:

http://codetrips.blogspot.com/search/label/gtest http://codetrips.blogspot.com/search/label/gtest

They helped me a lot on that topic. 他们在这个话题上给了我很多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM