Hi, <br><br>I'm new to eunit and I am trying to get a certain group of tests completed that require a setup and teardown. Specifically, I have an ets table that I would like to set up and then drop after each small test. The problem is, the eunit macro for this seems to be only performing the setup and teardown at the beginning of the series and at the end. I am using a "foreach", but it is acting like a "setup". I have some code below to illustrate what I am talking about:<br>
<br>db_functions_test_() -><br> {foreach,<br> fun()-><br> {ets:new(usertable,[set,public]),<br> ets:new(addrtable,[set,public])}<br> end,<br> fun({Users,Addrs})-><br> ets:delete(Users),<br>
ets:delete(Addrs)<br> end,<br> [fun db_test_list_/1]<br> }.<br><br>db_test_list_(Tables) -><br> [{"Add user to empty table",<br> ?_assertMatch(user_added,fastrets:add_user(Tables,"Test",{'localhost',4000}))},<br>
{"Get all users from empty table",<br> ?_assertMatch([],fastrets:get_all_users(Tables))},<br><*Lots more tests here -snip-*><br><br>I am using this particular form since I need the ets table info for the functions in the fastrests module, so I need to be able to initialize each of the tests with the newly generated data. In this case, the behavior I am getting is that the second test is failing to find an empty list because the first test added a user and wasn't cleaned up. I understand that ets is not garbage collected, so could it be that it is simply not possible to do these tests in the manner I am attempting? Also, I am fairly new to unit testing in general (I am a student) and eunit in particular, so if there is a more idiomatic or reasonable way to do what I am trying to do, I am all ears.<br>
<br>Thanks,<br><br>Josh Kuhn<br><br>