Unit testing tightly coupled structures

⚓ Rust    📅 2026-02-27    👤 surdeus    👁️ 1      

surdeus

Hi folks,

I try to write some unit tests for my program. I have a Decoder struct I want to test, which reads a socket and implements a protocol. One of its fields is MainExecutor, which Decoder uses to do stuff according to what Decoder::decode() reads (i.e. when a command 'turn on the light' comes, executor.turn_on_light() is invoked). How can I mock MainExecutor, if it is a field in Decoder? Or shall I use mpsc to pass the commands (perhaps enum variants) from Decoder to the Executor, in order to decouple them? Or can perhaps a crate like mockall be useful in this situation?

1 post - 1 participant

Read full topic

🏷️ Rust_feed