Skip to content

Writing tests for the testing framework

jkamins7 edited this page Jul 26, 2021 · 9 revisions

Setup Docker

You will need to get docker set up on your computer only once, and pull once each time the main branch is updated.

Download Docker

https://www.docker.com/products/docker-desktop

Pull Docker image

From a terminal, run

docker pull hopkinsidd/choleramappingpipeline

Mac Specific configuration

  1. Open Docker
  2. Click the gear icon in the upper right hand corner
  3. Click Resources from the menu on the left
  4. Ensure that Memory is at least 4GB (default on mac is 2GB). You may want to set more memory if you are doing larger tests, but at least 4GB is required for compiling the STAN model

Start a docker session

  1. Clone this repository in a local directory
  2. Run docker run -it -v <absolute path to local cholera-mapping-pipeline directory>:/home/app/cmp hopkinsidd/choleramappingpipeline

Making changes to files in cholera-mapping-pipeline

Any changes you make to files in your cholera-mapping-pipeline directory will also be made on docker and vice versa.

Run tests

  1. Create environment variables for your api key and username
    • export CHOLERA_API_USERNAME=<your_email@wherever>
    • export CHOLERA_API_KEY=<your_api_key>
  2. Document and install taxdat
    • cd ~/cmp/packages/taxdat
    • Rscript -e 'devtools::document()'
    • Rscript -e 'install.packages(".", type = "source", repos = NULL)'
  3. Run tests
    • cd ~/cmp/packages/taxdat && Rscript -e 'devtools::test()'
    • cd ~/cmp/tests && Rscript testthat.R
    • cd ~/cmp/Analysis/R && Rscript run_test.R

Write your own tests

Start by making a copy of run_test.R as the basis for your test. There are lines you can modify (or remove) about how to create the different parts of your test case using the simulation framework. For some of the more complicated functions, only the default arguments are used and you'll need to use Rstudio's help or ? to see the rest of the arguments. There are examples of arguments for these functions in create_standardized_testing_data.R