[erlang-questions] testing strategy question.

Erik Søe Sørensen <>
Wed Feb 13 10:08:58 CET 2013


Eunit has a similar thing.
They call it "fixtures":
http://www.erlang.org/doc/apps/eunit/chapter.html#Fixtures
Den 13/02/2013 09.05 skrev "Huseyin Yilmaz" <>:

> Hi, I am relatively new to erlang and I am trying to write a project to
> grasp the language and otp basics. In my application, I am using e-units
> for testing. here is some sample code
>
>
> get_room_get_code_test() ->
>     chat:stop(),
>     Code = 1,
>     ?assertEqual(ok, chat:start()),
>     {ok, Room} = start_link(Code),
>     ?assertEqual({ok, 1}, get_code(Room)),
>     ?assertEqual({ok, Room}, get_room(1)),
>     ?assertEqual(ok, chat:stop()).
>
>
> all of my codes have this structure.
>
> 1) Stop chat server, if it is running (if previous test failed before
> stopping running server)
> 2) Start chat server.
> 3) do tests.
> 4) stop server.
>
>
> Writing this every time is look really bad. (even if would make
> start_test_env, stop_test_env methods, I would still need to write a
> structure to make sure test environment is properly destroyed for every
> failed test.)
>
> So I decided to write it with common test.
>
> init_per_suite(Config) ->
>     ok = chat:start(),
>     error_logger:info_msg("Chat application stopped~n"),
>     Config.
>
> end_per_suite(_Config) ->
>     ok = chat:stop(),
>     error_logger:info_msg("Chat application stopped~n"),
>     ok.
>
> get_room_get_code_test_case() ->
>     [].
>
> get_room_get_code_test_case(_Config) ->
>     Code = 1,
>     {ok, Room} = c_room:start_link(Code),
>     {ok, Code} = c_room:get_code(Room),
>     {ok, Room} = c_room:get_room(1).
>
>
>
> With common  tests my tests seems a lot better. But if I have an error to
> console. instead of it goes to common test report.
>
> I was wondering what people are using in those situations.
>
> What I want to do is to run the test cases every time I save my files to
> see if anything is broken. So I do not really want to run the test cases
> and go to my browser to see the results every time I save a file.
>
> Another thing is ?assert macros.  Those macros give a nice output in
> eunits but common_tests does not have them. So it seems to me like we do
> not really interested in common_test output. we only want to see if it
> tests. So this means they are only for to run before going production?
>
> Any comment on this would be appreciated.
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130213/cd30f421/attachment.html>


More information about the erlang-questions mailing list