ShimForge Lets Rust Developers Mock Functions in Tests Without Changing Production Code
A new Rust development library called ShimForge allows developers to replace function calls during unit tests without modifying production code or introducing test-only traits. The tool addresses a common pain point where testing error paths — such as filesystem, clock, or FFI calls — forces developers to add generic parameters and abstractions solely for testing purposes. ShimForge is added as a development dependency and works by intercepting specific function calls within a test session, letting developers control return values and verify call counts or arguments. It supports mocking normal functions, methods, generic instantiations, unsafe functions, and foreign function interface calls. The library also provides a simpler replace! macro for cases where full expectation matching is not required.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in