Eavesdropping on GenServers Via Tracing
“How can I verify, during testing, that a GenServer or process received a message?” I have asked myself that on a number of occasions while working with Elixir, especially when interacting with dependencies outside of my control that generate processes and GenServers. There are many answers to the question, including but not limited to:
- creating a module that delegates calls to the dependency and using the project’s test config to swap in a mock module
- passing a mock module or GenServer directly to the caller you wish to test
- using Mox for general mocking
- using erlang’s trace/3 on the target GenServer and monitoring its messages
trace/3
function.
Read →