[erlang-questions] Mocking I/O calls - defining sequence of returns
Alyssa Kwan
alyssa.c.kwan@REDACTED
Mon May 23 20:25:41 CEST 2011
Hi everyone!
Thanks to everyone for all of your help!
I'm writing a REPL for s-expressions, which I've implemented using io:get_line using the same arguments for every line. So unit testing called for returning a sequence of values for each call, which were identical.
I was able to do what I want with meck using meck:history.
FYI, the process dictionary solution doesn't work with meck because the fun passed in doesn't execute in the same process as the test process.
I haven't had a chance to try Sven Heyll's erlymock, because I can't get maven-erlang-plugin to work on my box yet, but I think I'll be migrating to that once I do. I like the approach of explicitly declaring a mock object, which allows tracking of call order over multiple mocked modules. That's key for testing state-changing units which mocks are good for. Also, funs are supposedly executed in the test process, which allows for better error reporting in the console (I'm using rebar eunit).
However, AFAIK, erlymock doesn't allow passthrough, which isn't nice. I'm going to try to work on extending that. Building in support for a sequence of returns would also be nice.
Thanks!
Alyssa
More information about the erlang-questions
mailing list