#| include: false
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

What is webfakes?

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.

Webfakes vs mocking

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:

Webfakes vs the real API

Webfakes vs httpbin.org

Using webfakes::httpbin_app() with testthat


You can also create a web server for a test file, or even for a single test case. See vignette("how-to") for details how.

Writing apps

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.




gaborcsardi/pressr documentation built on June 2, 2025, 2:10 a.m.