Question

Most of my code looks like this

handle_event({publish,Publish_Msg,Publishing_Channel},State)->

Member = pg2:get_members(helpers:get_channel_name(Publishing_Channel)),
case Member of 
    [M|O]->
        [Pid!{send,Publish_Msg}||Pid<-[M|O]];
    {error,_}-> lager:info("unavailable")
end,
{ok,State};

The above handler gets called for publish event and all it does is it sends a message to a process id.

What I would like to do is create a bunch of mock Pids and and then have this event handler send data to those. And check if the data is actually received by them. Is there any way to do this with EUNIT. Or is there a better way to test event handlers?

Was it helpful?

Solution

use Common Test (1) which lets you start your gen_event per testcase/group/suite. It's powerful and well documented, and also the book Learn you some Erlang (2) has a great chapter about it.

(1): http://www.erlang.org/doc/man/common_test.html

(2): http://learnyousomeerlang.com/common-test-for-uncommon-tests

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top