1

我有一个失败的测试。我做了一些更改,撤消了它们,再次运行我的测试。我没有失败,而是得到了这个。

我的所有.beam文件都存在。我的git status显示没有变化。

=====================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.
error
60> room:test().

=ERROR REPORT==== 14-Feb-2017::19:36:57 ===
** Generic server <0.1375.0> terminating
** Last message in was {join,#{auth => "auth",name => "Blandline"}}
** When Server state == {<0.1376.0>,<0.1379.0>,<0.1380.0>}
** Reason for termination ==
** {function_clause,
       [{table,terminate,
            [{{case_clause,{ok,#{x => "Blandline"}}},
              [{table,handle_call,3,[{file,"table.erl"},{line,15}]},
               {gen_server,try_handle_call,4,
                   [{file,"gen_server.erl"},{line,615}]},
               {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,647}]},
               {proc_lib,init_p_do_apply,3,
                   [{file,"proc_lib.erl"},{line,247}]}]},
             {<0.1376.0>,<0.1379.0>,<0.1380.0>}],
            [{file,"table.erl"},{line,47}]},
        {gen_server,try_terminate,3,[{file,"gen_server.erl"},{line,629}]},
        {gen_server,terminate,7,[{file,"gen_server.erl"},{line,795}]},
        {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]}
room: firstMove_test...*skipped*
undefined
*unexpected termination of test process*
::{function_clause,[{table,terminate,
                           [{{case_clause,{ok,#{x => "Blandline"}}},
                             [{table,handle_call,3,[...]},
                              {gen_server,try_handle_call,4,...},
                              {gen_server,handle_msg,...},
                              {proc_lib,...}]},
                            {<0.1376.0>,<0.1379.0>,<0.1380.0>}],
                           [{file,"table.erl"},{line,47}]},
                    {gen_server,try_terminate,3,
                                [{file,"gen_server.erl"},{line,629}]},
                    {gen_server,terminate,7,
                                [{file,"gen_server.erl"},{line,795}]},
                    {proc_lib,init_p_do_apply,3,
                              [{file,"proc_lib.erl"},{line,247}]}]}

=======================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.
error

s:s 只是gen_server:call. 我正在测试这个模块的其他模块。

-module(room).
-behaviour(gen_server).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").

testRoom() ->
  {ok, R} = room:go(),
  {ok, T, _} = s:s(R, {join, #{name => "Blandline", auth => "auth"}}),
  {ok, T, _} = s:s(R, {join, #{name => "Kreutzer", auth => "auth"}}),
  {R, T}.

firstMove_test() ->
  {R, T} = testRoom(),
  {ok, #{actions := _, board := _, clock := _}} = s:s(R, {play, T, {take, x, {1,2}}, {"Blandline", "auth"}}).

badMove_test() ->
  {R, T} = testRoom(),
  {error, invalid_input} = s:s(R, {play, T, {take, x, {1,2,3}}, {"Blandline", "auth"}}).

badAuth_test() ->
  {R, T} = testRoom(),
  {error, invalid_auth} = s:s(R, {play, T, {take, x, {1,2}}, {"Blandline", "badauth"}}).

badTable_test() ->
  {R, _} = testRoom(),
  {error, bad_table} = s:s(R, {play, self(), {take, x, {1,2}}, {"Blandline", "badauth"}}).
4

1 回答 1

1

正如错误报告告诉你的那样:

[{{case_clause,{ok,#{x => "Blandline"}}},
    [{table,handle_call,3,[{file,"table.erl"},{line,15}]},

您在文件 table.erl 第 15 行中有一个不匹配的 case 子句:-)

认为尽管您撤消了更改,但测试开始失败的原因是因为您正在从 Erlang shell 运行测试,并且您有一些东西(如 gen_server)仍在运行,但由于某些原因而失败。

换句话说,您的测试是不可重复的,因为它们要么没有正确地分解所有依赖项,要么因为它们需要在运行测试之前在 Erlang shell 中手动启动像这个 gen_server 这样的外部依赖项。

我强烈建议忘记运行测试的 Erlang shell。使用 rebar3 从终端构建和运行测试。这将迫使您处理所有依赖项并进行健壮的测试。完成这项工作所花费的时间将得到充​​分利用:-)

于 2017-02-15T18:05:42.117 回答