Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mockr to write unit tests #14

Open
isteves opened this issue Jun 1, 2018 · 3 comments
Open

Use mockr to write unit tests #14

isteves opened this issue Jun 1, 2018 · 3 comments
Assignees
Labels
backlog The issue has been put on the back burner enhancement New feature or request
Milestone

Comments

@isteves
Copy link
Collaborator

isteves commented Jun 1, 2018

From #13:

For your issue of wanting to test your processing code with a formal unit test, your intuition is right on. The way people like to do this is to make what's called a mock. It's basically what you said: save a copy of some response to some function call that usually is slow/can fail/etc and test that. This makes unit test unit tests and not integration tests!

I haven't done this directly with testthat, but there appears to be support: https://github.com/r-lib/testthat/blob/master/R/mock.R. Also see https://www.mango-solutions.com/blog/testing-without-the-internet-using-mock-functions.

@isteves isteves added the backlog The issue has been put on the back burner label Jun 25, 2018
@isteves
Copy link
Collaborator Author

isteves commented Aug 14, 2018

Possibly helpful resource: https://enpiar.com/talks/api-in-r/

@amoeba
Copy link
Collaborator

amoeba commented Oct 22, 2018

https://github.com/ropensci/vcr just got httr support so this could be away to go too. Not sure how to choose between available options yet. Yet!

@amoeba amoeba added this to the v1.0 milestone Feb 26, 2020
@amoeba amoeba self-assigned this Feb 26, 2020
@amoeba
Copy link
Collaborator

amoeba commented Mar 3, 2020

I took a look at this during the pre-1.0 refactor and tried out vcr. I ran into an issue I couldn't work around that may have something to do with RT's use of session cookies and our use of httr's built-in cookie caching functionality. I've ping Scott Chamberlain (creator of the vcr R package).

At this point, the API wrappers with more complicated logic make use of helper functions, some of which have been factored out and are unit tested separately. Otherwise, we have integration / end-to-end tests set up to run via GitHub Actions and they can also be run locally with Docker.

Doing more refactoring and/or integrating mocks or vcr may be of benefit but I think, at this point, the package is pretty well tested so I'm going to move this to the next milestone.

@amoeba amoeba modified the milestones: v1.0, Next release Mar 3, 2020
@amoeba amoeba added the enhancement New feature or request label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog The issue has been put on the back burner enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants