| Author |
Message |
< Advanced Erlang/OTP ~ erlymock+eunit problems with file, ets |
| jwatte |
Posted: Sat Oct 09, 2010 6:36 am |
|
|
|
User
Joined: 10 Feb 2010
Posts: 34
|
I've been using eunit and erlymock (the Jason Wagner version) for testing for a while, and overall, I think they work pretty well!
However, because erlymock uses temporary code replacement for named modules, you can't mock any module that erlymock in turn uses. And, because it uses the compiler to do its dirty work, this means you can't mock things like ets or file, or the internals will try to call the replaced version and badness ensues. (At least, that's what I think is happening)
Here are two cases:
Code: some_test() ->
erlymock:start(),
erlymock:strict(file, delete, ["somename"], [{return, ok}]),
erlymock:replay(),
ok = my_function_that_calls_delete("somename"),
ok = erlymock:verify().
another_test() ->
erlymock:start(),
erlymock:strict(ets, new, [some_table, '_'], [{return, some_table}]),
erlymock:replay(),
ok = my_function_that_calls_ets_new(),
ok = erlymock_verify().
These cases will cause internal errors in erlymock and the subsystems it uses, rather than actually provide mocking for the given modules while testing the functions in question.
Does anyone have any good ideas about what to do about this?
Worst case, I think I can let it call the 'real' ets, because it's fairly fast and non-destructive (except for named tables), but for the file system, that's a lot harder. I really don't want to wrap all file system access into my own module... |
|
|
| Back to top |
|
| jwatte |
Posted: Tue Nov 09, 2010 5:56 am |
|
|
|
User
Joined: 10 Feb 2010
Posts: 34
|
What I ended up doing, for the functions I really must have tests for, is pass in the module name to use for file I/O as an argument.
Code: my_fun(Whatever) ->
file:somecall(...).
turns into
Code: my_fun(Whatever) ->
my_fun(Whatever, file).
my_fun(Whatever, File) ->
File:somecall(...).
This allows me to mock an arbitrary module name in erlymock, and pass that in as the "File" module to use:
Code: my_fun_test() ->
erlymock:start(),
erlymoc:strict(test_file, somecall, ...),
erlymock:replay(),
my_fun(whatever, test_file),
erlymock:verify().
Not particularly elegant, and probably less efficient for the compiler, too, but testing and correctness has to go before elegance and performance... |
|
|
| Back to top |
|
| wuji |
Posted: Fri Sep 14, 2012 6:19 am |
|
|
|
User
Joined: 10 Aug 2012
Posts: 654
|
Regional Jail in Los Angeles, Villanueva said. Young was being held at at cheap jordans for sale at the same location on $1 million bail.MTV Reality 'Gangsta' Charged With
in MiamiBaron 'Dirty' Colon, Star of 'From G's to Gents,' Accused of of jordan concord of Killing ArtistBy RUSSELL GOLDMANJan 15, 2011 A two-bit "gangster" who appeared
a third-rate reality show is now charged with first degree murder.Baron "Dirty" "Dirty" jordan 11 "Dirty" Colon, a 24-year-old barber and finalist in the 2009 MTV program
G's to Gents," was arrested on Jan. 7 in connection with the the cheap jordan shoes the fatal armed robbery of a Florida artist in 2006.Colon appeared on
second season of the show, produced by actor Jamie Foxx, in which which [h4]jordan 11[/h4] which young men with checkered pasts -- so-called "g's" or "gangstas" --
to turn their lives around and become "gentlemen.""I got two kids. I I cheap designer *beep* I want to be in the gentleman's club because I want to
for them," Colon said in the season's first episode. "If I don't don't jordan 11 don't change, there's only going to be two things: prison or death."Prison |
|
|
| Back to top |
|
| mbtshoes88 |
Posted: Wed Sep 19, 2012 8:46 am |
|
|
|
User
Joined: 18 Sep 2012
Posts: 30
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|