This is an old revision of the document!
OHDSI unit testing for R follows the standard R practice using test_that: A folder named 'tests' is created in the root of the package, and this folder contains
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) })
Unit tests are triggered when
Your collaborators will appreciate it if you make sure the package passes check before pushing changes to the repository.
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:
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 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 here.