From f449a78df364a8f39afcd74cc6f6fe8cb224c520 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Sun, 12 Jan 2020 16:59:46 -0600 Subject: [PATCH] [R-package] Added instructions for generating R test coverage (#2664) --- .gitignore | 3 +++ R-package/README.md | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/.gitignore b/.gitignore index c0cf2389d..59a7ff663 100644 --- a/.gitignore +++ b/.gitignore @@ -321,6 +321,9 @@ nosetests.xml coverage.xml *,cover .hypothesis/ +**/coverage.html +**/coverage.html.zip +R-package/tests/testthat/Rplots.pdf # Translations *.mo diff --git a/R-package/README.md b/R-package/README.md index 728d97377..ead8c992a 100644 --- a/R-package/README.md +++ b/R-package/README.md @@ -126,6 +126,30 @@ Please visit [demo](https://github.com/microsoft/LightGBM/tree/master/R-package/ * [Leaf (in)Stability](https://github.com/microsoft/LightGBM/blob/master/R-package/demo/leaf_stability.R) * [Weight-Parameter Adjustment Relationship](https://github.com/microsoft/LightGBM/blob/master/R-package/demo/weight_param.R) +Testing +------- + +The R package's unit tests are run automatically on every commit, via integrations like [Travis CI](https://travis-ci.org/microsoft/LightGBM/) and [Azure DevOps](https://dev.azure.com/lightgbm-ci/lightgbm-ci/_build). Adding new tests in `R-package/tests/testthat` is a valuable way to improve the reliability of the R package. + +When adding tests, you may want to use test coverage to identify untested areas and to check if the tests you've added are covering all branches of the intended code. + +The example below shows how to generate code coverage for the R package on a macOS or Linux setup, using `gcc-8` to compile `LightGBM`. To adjust for your environment, swap out the 'Install' step with [the relevant code from the instructions above](#install). + +```shell +# Install +export CXX=/usr/local/bin/g++-8 +export CC=/usr/local/bin/gcc-8 +Rscript build_r.R + +# Get coverage +rm -rf lightgbm_r/build +Rscript -e " \ + coverage <- covr::package_coverage('./lightgbm_r', quiet=FALSE); + print(coverage); + covr::report(coverage, file = file.path(getwd(), 'coverage.html'), browse = TRUE); + " +``` + External (Unofficial) Repositories ----------------------------------