ropensci-books / http-testing

HTTP testing for R
https://books.ropensci.org/http-testing/
Creative Commons Zero v1.0 Universal
53 stars 17 forks source link

when comparing the three packages #51

Closed maelle closed 3 years ago

maelle commented 4 years ago
maelle commented 4 years ago

Topics for the comparison

maelle commented 4 years ago
maelle commented 4 years ago

Reg recording by hand https://github.com/maelle/exemplighratia/pull/3#discussion_r509861774

maelle commented 4 years ago

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.

maelle commented 4 years ago

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)

sckott commented 4 years ago

Interesting on the differences, thanks @maelle

maelle commented 3 years ago

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.

maelle commented 3 years ago

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?

maelle commented 3 years ago

another point of interest, can you POST data and GET it.

sckott commented 3 years ago

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

sckott commented 3 years ago

answer about post then get in slack

maelle commented 3 years ago

Oooh could one improve this by

sckott commented 3 years ago

have tests live in testthat/fixtures

I don't like this idea.

We can keep thinking though

maelle commented 3 years ago

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)

sckott commented 3 years ago

Right