Permalink
Browse files

Include fixture setup and cleanup errors in Eunit Surefire report

An error during fixture setup means that some tests could not be run,
and therefore needs to be highlighted in the test report.  Likewise, a
cleanup failure is often a problem that needs to be looked into.

Since setup and cleanup are not part of any single test in Eunit's
view, I include them as phantom test cases in the report whenever they
fail.
  • Loading branch information...
1 parent 5e99c21 commit 2318cc9eed2056805f40e7e71dfc11d6a9288aba @legoscia legoscia committed with Richard Carlsson Mar 10, 2011
Showing with 27 additions and 3 deletions.
  1. +27 −3 lib/eunit/src/eunit_surefire.erl
View
30 lib/eunit/src/eunit_surefire.erl
@@ -156,9 +156,33 @@ handle_end(test, Data, St) ->
St#state{testsuites=store_suite(NewTestSuite, TestSuites)}.
%% Cancel group does not give information on the individual cancelled test case
-%% We ignore this event
-handle_cancel(group, _Data, St) ->
- St;
+%% We ignore this event...
+handle_cancel(group, Data, St) ->
+ %% ...except when it tells us that a fixture setup or cleanup failed.
+ case proplists:get_value(reason, Data) of
+ {abort, {SomethingFailed, Exception}}
+ when SomethingFailed =:= setup_failed;
+ SomethingFailed =:= cleanup_failed ->
+ [GroupId|_] = proplists:get_value(id, Data),
+ TestSuites = St#state.testsuites,
+ TestSuite = lookup_suite_by_group_id(GroupId, TestSuites),
+
+ %% We don't have any proper name. Let's give all the
+ %% clues that we have.
+ Name = case SomethingFailed of
+ setup_failed -> "fixture setup ";
+ cleanup_failed -> "fixture cleanup "
+ end
+ ++ io_lib:format("~p", [proplists:get_value(id, Data)]),
+ Desc = format_desc(proplists:get_value(desc, Data)),
+ TestCase = #testcase{
+ name = Name, description = Desc,
+ time = 0, output = <<>>},
+ NewTestSuite = add_testcase_to_testsuite({error, Exception}, TestCase, TestSuite),
+ St#state{testsuites=store_suite(NewTestSuite, TestSuites)};
+ _ ->
+ St
+ end;
handle_cancel(test, Data, St) ->
%% Retrieve existing test suite:
[GroupId|_] = proplists:get_value(id, Data),

0 comments on commit 2318cc9

Please sign in to comment.