Ask Your Question

gtest problem with main function

asked 2013-06-01 02:59:35 -0500

madmax gravatar image

updated 2013-06-01 23:15:57 -0500


I have a line.cpp with a main function and some other functions I want to test.
Then I have my utest.cpp with my test cases and another main function to call them.

A solution would be to just comment the main function and then test, but that is not the solution I am looking for.
I understand that I can not have multiple main files in my project, but how can I test my functions? Because in the robot_pose_ekf package, there are also two main files and it works.

The CMake relevant part looks like this:

rosbuild_add_executable(line src/line.cpp)

rosbuild_add_gtest(test/utest test/utest.cpp)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-06-02 14:34:13 -0500

joq gravatar image

A simple solution is to move the functions you want to test into another source file, with a header to declare their interfaces. You can compile that into a library or just add it to the source file lists of both the line and test/utest targets.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-06-01 02:59:35 -0500

Seen: 1,149 times

Last updated: Jun 02 '13