0
$\begingroup$

Rosanswers logo

Hi,

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)

Originally posted by madmax on ROS Answers with karma: 496 on 2013-06-01

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by joq with karma: 25443 on 2013-06-02

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.