earthlab / qtoolkit

An R package that allows you to efficiently access, plot and analyze survey data via the Qualtrics API.
BSD 3-Clause "New" or "Revised" License
6 stars 2 forks source link

Adding unit tests #16

Open mbjoseph opened 6 years ago

mbjoseph commented 6 years ago

Currently this package has no unit tests!

Proposed path forward

(feel free to comment @lwasser and @1papaya)

It seems like a reasonable starting point would be to begin with the API-oriented functions (e.g., those in R/api.R. For security reasons we should probably rely on the assumption that the person doing the testing has provided their api credentials in their ~/.Rprofile file, so that we don't have any API keys floating around in the unit tests.

Some of these tests are going to be easier to write than others. For example, testing qapi_get_base_url should be simple, but testing all of the functionality in qapi_connect will be more difficult because we need to keep API keys secret.

Once these functions are tested, testing the rest of the package should be easier, since many of the functions in main.R are wrappers around the functions in api.R.

There are some great instructions on how to get started with adding tests for an R package here: http://r-pkgs.had.co.nz/tests.html

lwasser commented 6 years ago

Hey @mbjoseph thank you so much for this feedback !! once the package is back up and running we will focus on unit tests. Question for you. What do you think about the ease of someone editing their .Rprofile doc? On one hand, i do think it's a good option because it keeps api keys out of working directories which we dont want. On the other, that is a hidden file so it takes a bit of knowledge to find it. Any thoughts?

One thought i had was something like what you do wtih the twitter api where we write a small function that takes the required info (org id and token) and adds it to the .Rprofile ofcourse.. there are some danger zone elements there... thoughts?

mbjoseph commented 6 years ago

I like the .Rprofile option over using a function in R, since it is less likely to place credentials in an .Rhistory file and get accidentally committed, but both options can be secure!