I use mock objects extensively in my unit testing. But now I need to mock a type that is Send and Sync, and I can’t do it. None of the mock libraries I checked (galvanic_mock, mock-it, pseudo, double, mock_derive, mockers, and simulacrum) can do it. I’ve tried mucking around with the Fragile crate. With difficulty, I think I can get it working for Send types, but not for Sync ones. Has anybody run into this problem before?

Here’s a minimal example with Mockers. It doesn’t work of course, which is why it’s commented out. The basic idea is "create a mock for trait T, then turn it into a trait object for T + Send.github.com

But I came up with another “solution” after getting no response for 24h. My “solution” is incredibly lame. I use Simulacrum to create a mock structure, then cheat by implementing Send! It’s totally unsafe, but it works as long as my unit tests are all single-threaded. It looks a bit like this: