#| include: false knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Webfakes is an R package that can spin up web servers on your machine to facilitate testing R code. R code that needs an HTTP connection is not trivial to test:
With webfakes you can easily start a custom web app, that is running on the local machine.
Mocking is a general technique to mimic the behavior of a function or object that is needed in test case. In the case of HTTP requests, this typically means that both the request and its response are recorded when the tests run the first time, and saved to disk. Subsequent test runs intercept the HTTP requests, match them against the recorded requests and then replay the corresponding recorded response. See for example the vcr and httptest R packages.
The advantages of using your own webfakes server, over mocking:
https://httpbin.org
compatible app, chances are, you don't even need to write your testing app, just start writing tests right away.skip_if_offline()
.skip_if_offline()
.webfakes::httpbin_app()
app, so it is easy to switch from httpbin.org.webfakes::httpbin_app()
with testthatYou can also create a web server for a test file, or even for a single test case.
See vignette("how-to")
for details how.
If the builtin httpbin_app()
is not appropriate for your tests, you can write your own app.
You can also extend the httpbin_app()
app, if you don't want to start from scratch.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.