User Tools

Site Tools


development:unit_testing_in_r

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
development:unit_testing_in_r [2015/06/30 03:24]
schuemie
development:unit_testing_in_r [2020/04/06 13:51]
schuemie
Line 1: Line 1:
-OHDSI unit testing for R follows the standard R practice using test_thatA folder named '​tests'​ is created in the root of the package, and this folder contains +This has moved to https://ohdsi.github.io/MethodsLibrary/​developerGuidelines.html#​unit_tests
- +
-  * A sub-folder called '​testthat` +
-  * A file called '​testthat.R' +
- +
-The file '​testthat.R'​ should have the following content: +
- +
-  library(testthat) +
-  library(<​package name>) +
-  test_check("<​package name>"​) +
- +
- +
-The sub-folder '​testthat` should contain one or more R scripts whose file name starts with '​test-'​ (e.g. '​test-connection.R'​. Each file should contain one or more `test_that` blocks, for example +
- +
- +
-  test_that("​Function x returns 2", { +
-    expect_equal(x(),​ 2) +
-  }) +
-   +
-   +
-==== When unit tests are performed ==== +
-Unit tests are triggered when +
-  * You manually perform a **check** of the R package (see the Build tab in R-Studio) +
-  * When the [[OHDSI Travis CI Server]] automatically builds the package after a push to the repository +
- +
-Your collaborators will appreciate it if you make sure the package passes check before pushing changes to the repository. +
-   +
-==== Code coverage ==== +
- +
-We use codecov in combination with the covr package to measure which lines of codes are covered by at least one unit test. Two additions need to be made to .travis.yml to enable code coverage: +
- +
-  * Add **- ./travis-tool.sh install_github jimhester/​covr** to the **install** section +
-  * Add **- Rscript -e '​library(covr);​codecov()'​** to the **after_success** section ​+
development/unit_testing_in_r.txt · Last modified: 2020/04/06 13:51 by schuemie