[erlang-questions] testing strategy question.

Huseyin Yilmaz yilmazhuseyin@REDACTED
Wed Feb 13 09:05:20 CET 2013

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() ->
    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"),

end_per_suite(_Config) ->
    ok = chat:stop(),
    error_logger:info_msg("Chat application stopped~n"),

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130213/a4e6e31c/attachment.htm>

More information about the erlang-questions mailing list