I know there’s been an almost annual discussion of mocking in Rust on Reddit, though I have a specific question regarding implementation.
I have a really basic framework to help me mock parts of std::fs for unit tests. However I need some kind of mutable global that I can use to setup and monitor the state of the mocked fs module. I could use something like lazy-static, though as unit tests must be run in isolation, the global has to actually be ‘local’ to the thread running the test.
For example, if I mock out the function “fs::metadata”, I need to be able to tell it what path to expect, and check whether it has been called for a specific test, i.e. a specific thread.
I could solve this by doing away with the idea of global state and passing references around, though then I would have to create two function calls every time I interfaced with any module I wanted to mock - 1 for production and 1 for tests. That sucks!
Does anyone have any ideas, or is this a bad approach?