mockery
A mocking library for R.
The mockery package provides mocking and stubbing capabilities for R unit tests, allowing you to replace functions with test doubles during testing. It is primarily used to isolate code under test by controlling dependencies and verifying function interactions.
The package offers several advantages over alternatives like testthat’s with_mock: it supports mocking primitive functions, safely handles functions from base R packages without JIT compiler conflicts, and provides fine-grained control through depth parameters for nested function calls. Mock objects track how they were called, enabling assertions about call counts and arguments. However, the package is now superseded in favor of testthat::local_mocked_bindings() for new test code.

