[erlang-questions] testing strategy question.

Ola Bäckström Ola.Backstrom@REDACTED
Wed Feb 13 10:23:18 CET 2013

It is possible to combine and use the assert macros from eunit inside Commont test code.

Just bring all in:

                (+ all standard CT suite testcase setup stuff)
And then in a test function
should_work(_Config) ->
    ?assertEqual(ok, some:work()).

(you might get a warning like
.../ct/some_SUITE.erl:0: missing specification for function test/0,
but that is just eunit complaining, but Common Test will execute it nicely)

From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Huseyin Yilmaz
Sent: den 13 februari 2013 09:05
To: erlang-questions@REDACTED
Subject: [erlang-questions] testing strategy question.

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/ca731327/attachment.htm>

More information about the erlang-questions mailing list