[erlang-questions] EUnit masquerading as Common Test

Per Melin per.melin@REDACTED
Wed Apr 27 18:10:33 CEST 2011


I am not too happy about having half of my tests in EUnit and half in
Common Test. And CT does not suit our workflow very well.

EUnit is in my opinion quite capable even for system and integration
tests. Its biggest drawback for me is that it is a hassle when you
have a lot of setup and teardown of fixtures.

So I started thinking. What if you could write test modules that look
just like CT suites, but execute in EUnit? I started to build a
proof-of-concept, but then I think I took it a little farther than
that:
https://github.com/permelin/common_eunit

Obviously there is a lot of functionality from CT that is missing. But
at least I wasn't using any of that anyway. I have started to convert
my CT suites over and it is so far working beyond expectations.

Is this a silly idea? Does anyone else see a value in this?

Here is an example that you can run just as usual in EUnit with
eunit:test(demo_tests).

-module(demo_tests).

-include_lib("common_eunit/include/common_eunit.hrl").

suite() ->
    [{timetrap, {seconds, 5}}, % The entire suite cannot take longer.
     {node, slave1}].          % A slave node called slave1 is started
                               % on the same host, for the duration of
                               % the suite.

all() ->
    [alpha, {group, beta}, delta, epsilon].

groups() ->
    [{beta, [parallel, {repeat, 100}], [gamma]}].


%%% Setup and cleanup

init_per_suite(Config) ->
    % Set up fixtures here.
    Config.

end_per_suite(_Config) ->
    ok.

init_per_testcase(Config) ->
    % Set up fixtures here.
    Config.

end_per_testcase(_Config) ->
    ok.


%%% Tests

alpha(_Config) ->
    % Put test code here.
    ?assert(1 < 2).

gamma(_Config) ->
    % This test will run 100 times, in parallel. See groups/0.
    % Put test code here.
    ok.

delta() ->
    [{timetrap, 200}].
delta(_Config) ->
    % This test will abort if it takes longer than 200 ms.
    ok = timer:sleep(100).

epsilon() ->
    [{spawn, slave1}].
epsilon(Config) ->
    % This test will execute on the node slave1.
    Node = ?config(slave1, Config),
    ?assertEqual(node(), Node).



More information about the erlang-questions mailing list