Maybe it’s just my perspective, but I usually introduce a behaviour only when I need more than one implementation of the same “behavior”. Adding a behaviour solely to enable mocking in tests has always felt a bit off to me.
e.g.
defmodule Boo do
use Genserver
def get_market_data() do
....
end
end
vs
defmodule BooBehvaiour do
@callback get_market_data() :: data
end
defmodule Boo do
use GenServer
@behaviour BooBehvaiour
@impl
def get_market_data() do
....
end
end
Reading our discussion I think there’s also a chance we’re talking about two different things ![]()
Could you walk me through what I should do if I want to test a piece of logic that depends on Boo.get_market_data/0, but I don’t want to start a process or mock all the underlying HTTP/DB calls? I’d just like to mock the return value of get_market_data() function to keep the test simple and async - how would you approach that? adding behavior to Boo?


















