zz-jason/leanstore

Increase test coverage to 80%

Opened this issue · 0 comments

Background

Currently, the overall test coverage of LeanStore is very low. Increasing unit test coverage is essential for detecting bugs early, improving code quality, and providing confidence when making changes. It also serves as documentation, showing how the code is intended to work, and makes the codebase easier to maintain and refactor. Overall, comprehensive unit tests ensure robust, reliable, and maintainable software.

How to generate coverage report in HTML

Mainly, you can follow the build and test steps in the CI workflow to install necessary tools

# generate compile database wich cmake preset
cmake --preset debug_tsan

# build
cmake --build build/debug_tsan -j `nproc`

# run unit tests, generate coverage raw data
TSAN_OPTIONS="suppressions=$(pwd)/tests/tsan.supp" ctest --test-dir build/debug_tsan --output-on-failure -j 2

# generate coverage report in HTML format
gcovr -v -r . --html-details --output=coverage.html --exclude 'build/*' --exclude 'tests/*' --exclude 'benchmarks/*' --verbose

# start a simple HTTP server to view the HTML report.
# then you can view the coverage report in your browser at
# http://localhost:8000/coverage.xml
python3 -m http.server -d .

Methods to improve test coverage

  1. add unit tests in the tests directory, there are lots of test examples
  2. remove unused dead code