[erlang-questions] Mocking I/O calls - defining sequence of returns

Tobias Schlager <>
Sun May 22 05:45:44 CEST 2011


Hi,

you could try erlymock. It's usage is pretty much like easymock for java.

Link:
  * https://github.com/sheyll/erlymock

For your example you could write something like this:

M = em:new(),
em:strict(M, io, get_line, [prompt1], {return, "a line"}),
em:strict(M, io, get_line, [prompt2], {return, eof}),
em:replay(M),

... test code goes here ...

em:verify(M),

I don't know how other frameworks do it but mocking io:get_line with 
erlymock will purge the io module. So running your test from within an 
erlang shell will most likely break the running shell. Regarding this 
mocking the io module might not be a good idea.

Regards
Tobias

Am 21.05.2011 20:55, schrieb Edward Wang:
> Then you will implement your mock version of io:get_line that way. The
> mock framework merely dispatches the call. That's all.
>
> On May 22, 2011 2:40 AM, "Alyssa Kwan" <
> <mailto:>> wrote:
>  > I'm sorry, I wasn't being specific. Is there any way to mock a
> sequence of calls to the same function? Like if I call io:get_line (or a
> wrapper because it's protected), how do I get it to return a different
> value for the first call and the second call?
>  >
>  > Also, will it expect exactly two calls as well? And does meck record
> call order for different functions?
>  >
>  > On May 21, 2011, at 1:43 PM, Edward Wang wrote:
>  >
>  >> Try meck https://github.com/eproxus/meck
>  >>
>  >> I used it to mock inet:getifaddrs/0 etc.
>  >>
>  >> On Sun, May 22, 2011 at 1:31 AM, Alyssa Kwan
> < <mailto:>> wrote:
>  >> Hi everyone!
>  >>
>  >> Are there any mocking libraries written that allow you to expect a
> sequence of calls and return a different value for each call? A mocking
> library that allows passthrough would be ideal.
>  >>
>  >> Thanks!
>  >> Alyssa
>  >> _______________________________________________
>  >> erlang-questions mailing list
>  >>  <mailto:>
>  >> http://erlang.org/mailman/listinfo/erlang-questions
>  >>
>  >
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list