2014-11-23 5 views

답변

1

아마도 gen_servers의 단위 테스팅에 유용한 또 다른 접근법을 발견하게 될 것입니다. gen_server 프로세스를 실행하고 그 동작을 테스트하는 대신 gen_server 콜백을 직접 테스트 한 다음 상태 전이를 검사 할 수 있습니다. 예를 들어

: 당신이 정말 복잡한 상태 및 상태 전이를 다루는 경우 here 또한이 방법의

-module(foo_server). 

%% Some code skipped 

handle_call({do_stuf, Arg}, _From, State) -> 
    NewState = modify_state(
    {reply, {stuf_done, Arg}, NewState}. 

%% Some code skipped 

-ifdef(TEST) 

do_stuf_test_() -> 
    {setup, 
     fun() -> 
      {ok, InitState} = foo_server:init(SomeInitParams), 
      InitState 
     end, 
     fun(State) -> 
      ok = foo_server:terminate(shutdown, State) 
     end, 
     fun(State) -> 
      Result = foo_server:handle_call({do_stuf, hello}, undefined, State), 
      [ 
       ?_assertMatch({reply, {stuf_done, hello}, _}, Result) 
      ] 
     end 
    } 
}. 

-endif. 

참조 토론, 어쩌면 당신은 proper가 도움이 발견 될 것이다.