Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mikeferguson/code_coverage

ROS package to run coverage testing
https://github.com/mikeferguson/code_coverage

Last synced: 3 months ago
JSON representation

ROS package to run coverage testing

Awesome Lists containing this project

README

        

# code_coverage

ROS package to run coverage testing

## Examples

* The [robot_calibration](https://github.com/mikeferguson/robot_calibration) package uses this to generate coverage for C++ code using Travis-CI and Codecov.io

## Usage
To use this with your ROS package:

* Add code_coverage as a test depend in your package.xml
* Update your CMakeLists.txt, in the testing section add the following. **NOTE** the order of test targets and coverage macros:
```cmake
if(CATKIN_ENABLE_TESTING AND ENABLE_COVERAGE_TESTING)
find_package(code_coverage REQUIRED)
# Add compiler flags for coverage instrumentation before defining any targets
APPEND_COVERAGE_COMPILER_FLAGS()
endif()

# Add your targets here

if (CATKIN_ENABLE_TESTING)
# Add your tests here

# Create a target ${PROJECT_NAME}_coverage_report
if(ENABLE_COVERAGE_TESTING)
set(COVERAGE_EXCLUDES "*/${PROJECT_NAME}/test*" "*/${PROJECT_NAME}/other_dir_i_dont_care_about*")
add_code_coverage(
NAME ${PROJECT_NAME}_coverage_report
DEPENDENCIES _run_tests_${PROJECT_NAME}
)
endif()
endif()
```
* **Note**: The variable `COVERAGE_EXCLUDES` must have some content!
* Now you can build and run the tests (you need a debug build to get reasonable coverage numbers):

- if using CATKIN_MAKE:
```
catkin_make -DENABLE_COVERAGE_TESTING=ON -DCMAKE_BUILD_TYPE=Debug
catkin_make -DENABLE_COVERAGE_TESTING=ON -DCMAKE_BUILD_TYPE=Debug PACKAGE_NAME_coverage_report
```
- if using CATKIN_TOOLS:
```
catkin config --cmake-args -DENABLE_COVERAGE_TESTING=ON -DCMAKE_BUILD_TYPE=Debug
catkin build
catkin build PACKAGE_NAME -v --no-deps --catkin-make-args PACKAGE_NAME_coverage_report
```

* The output will print where the coverage report is located

## Python rostest Support

While the C++ interface and Python-based unit tests require no
modification to get coverage information, Python-based nodes
run from rostest launch files need a bit of additional
instrumentation turned on:

```xml






```

In the CMakeLists, you will need to pass this argument:

```cmake
add_rostest(example_rostest.test ARGS coverage:=ENABLE_COVERAGE_TESTING)
```