Closed maelle closed 3 years ago
Topics for the comparison
Reg recording by hand https://github.com/maelle/exemplighratia/pull/3#discussion_r509861774
Neal Richardson's quote about mock files "Good APIs don't change that often so I tend to be less worried about "what if they change the API and I don't notice?" or maybe I weigh the tradeoffs differently. I'd personally prefer to have clearer, more expressive tests using mocks that I've massaged rather than have tests I can run unchanged against the live API but that can't assert much about the resulting behavior."
So the trade-off is
vcr has more tooling around the first possibility even a re-recording intervals. httptest serves both workflows, but with less features around re-recording. presser doesn't even allow any sort of automatic recording.
So your view on these things can help you choose a package.
if you use vcr when testing for errors you use something that's entirely different, webmockr.
With httptest and presser the process for faking 502 errors is much more similar.
(on the topic of error, not that sequence of responses e.g. 502 502 200 are smooth with webmockr and presser but not httptest yet)
Interesting on the differences, thanks @maelle
reg debugging. how does one run code in the tests interactively whilst using the recorded response? I'm not too sure how I'd achieve that with vcr/httptest. With presser one would "just" start the app before running the code.
with httptest for debugging you'd use https://enpiar.com/r/httptest/reference/use_mock_api.html I suppose
@sckott how would one run code outside of tests, while still using a given cassette?
another point of interest, can you POST data and GET it.
how does one run code in the tests interactively whilst using the recorded response?
I do this by running the vcr_configuration()
code block in the test helper file, and just change the paths to fixtures/files to reflect the directory you're in, e.,g.,
if this is what's in helper-pkg.R
vcr::vcr_configure(dir = "../fixtures", write_disk_path = "../files")
and if you're current directory is the root of the package and tests are are in tests/
, then run
vcr::vcr_configure(dir = "tests/fixtures", write_disk_path = "tests/files")
and then when you run http requests wrapped in use_cassette
you'll use the recorded fixtures
answer about post then get in slack
Oooh could one improve this by
have tests live in testthat/fixtures
I don't like this idea.
We can keep thinking though
Yeah one would just need a function that returns the right path to tests/fixtures no matter where it is called from (from tests/testthat or from the root)
Right
http://veekaybee.github.io/2019/02/10/lockin/
In presser docs https://r-lib.github.io/presser/articles/introduction.html#presser-vs-mocking " Better test writing experience. This is subjective, and your mileage may vary."