Question

Here's what I've tried:

In project properties I have included libgtest_main.a and libgtest.a under the libaries tab.

In run configurations under the C++ Unit tab, I have set C/C++ testing to 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.

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.

Hope someone can help - I've been at this for hours and it seems like something simple I've missed.

Was it helpful?

Solution

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 (i.e. /tmp/gtest-1.5.0)

I dont know if it is the best solution but it worked for me.

OTHER TIPS

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.

Next, in case of running tests inside eclipse. Please note that you need to set your run configuration to binary file with main function which runs tests (one presented by you). 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

They helped me a lot on that topic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top