This shows you the differences between two versions of the page.
Next revision | Previous revision Last revision Both sides next revision | ||
development:unit_testing_in_r [2015/06/30 03:09] schuemie created |
development:unit_testing_in_r [2015/06/30 03:31] schuemie |
||
---|---|---|---|
Line 17: | Line 17: | ||
expect_equal(x(), 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 | ||
+ | |||
+ | ==== Testing functions requiring database access ==== | ||
+ | |||
+ | On the OHDSI Jenkins server there are 6 databases that can be accessed from within a unit test, for the 3 main platforms (SQL Server, Oracle, PostgreSQL), and the two main versions of the [[documentation:cdm|Common Data Model]] (versions 4 and 5). To access the databases locally, you'll need to specify several environmental variables. These environmental variables should also be available on the [[OHDSI Travis CI Server]]. | ||
+ | |||
+ | Some example code in the DatabaseConnector package can be found [[https://github.com/OHDSI/DatabaseConnector/blob/master/tests/testthat/test-connection.R|here]]. |