8

使用 Python 时,我使用 python-coverage 之类的工具测试代码覆盖率,特别是对于 django 包 djaango-nose,我正在寻找 Erlang 中的等价物。我已经用 eunit 进行了测试并用surefire生成了我的报告,但是我没有找到一种方法来进行代码覆盖,有没有人知道这样做的工具或方法?

4

2 回答 2

11

如果你rebar只是添加:

{cover_enabled, true}.

给你的rebar.config

于 2013-07-10T09:24:11.607 回答
10

我使用 common test 来控制测试套件,然后在测试规范中您可以使用元组 {cover,"coverspec path"} 声明一个覆盖规范:

{include, ["../include"]}.
{suites,"../test", all}.
{logdir,"../results"}.
{cover,"../test/reduce.coverspec"}.

封面规范主要定义了详细程度和您要分析的模块列表:

{level, details}.
{incl_mods, [calc,calc_store]}.

然后,当您运行测试时,您会得到一个增量网页,其中包含完成的所有测试迭代,以及每个结果和覆盖率摘要的链接,然后您的源代码注释了一行的时间数评估。

增量网页 结果总结 报道摘要

和带注释的来源:

File generated from d:/documents and Settings/xxxxxxx/My Documents/git/calc/ebin/../src/calc_store.erl by COVER 2012-06-01 at 10:23:45

****************************************************************************

        |  -module(calc_store).
        |  
        |  -behaviour(gen_server).
        |  
        |  -record(state,{var,func}).
        |  -define(SERVER,?MODULE).
        |  
        |  %% gen_server call back
        |  -export([code_change/3,handle_call/3,handle_cast/2,handle_info/2,init/1,terminate/2]).
        |  
        |  %% api
        |  -export([start_link/0,storevar/2,storefunc/4,getvalue/1,getfunc/1,stop/0]).
        |  
        |  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        |  
        |  storevar(Name,Value) ->
     1..|      gen_server:cast(?MODULE,{storevar,Name,Value}).
        |  
        |  storefunc(Name,Par,Desc,Text) ->
     3..|      gen_server:cast(?MODULE,{storefunc,Name,Par,Desc,Text}).
        |  
        |  getvalue(Name) ->
    67..|      gen_server:call(?MODULE,{readvar,Name}).
        |  
        |  getfunc(Name) ->
    10..|      gen_server:call(?MODULE,{readfunc,Name}).
        |  
        |  stop() ->
     0..|   gen_server:cast(?MODULE,stop).
        |  
        |  start_link() -> 
     1..|      gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
        |  
        |  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        |  
        |  init([]) -> 
        |      %% register(?MODULE,self()),
     1..|      {ok,#state{var=dict:new(),func=dict:new()}}.
        |  
        |  handle_call({readvar,Name}, _From, State = #state{var=D}) -> 
    67..|      Reply = dict:find(Name,D), 
    67..|      {reply, Reply, State};
        |  handle_call({readfunc,Name}, _From, State = #state{func=F}) -> 
    10..|      Reply = dict:find(Name,F) , 
    10..|      {reply, Reply, State};
        |  handle_call(Request, From, State) -> 
     0..|      io:format("calc_store received call: ~p from ~p~n",[Request,From]),
     0..|      Reply = ok, 
     0..|      {reply, Reply, State}.
        |  
        |  handle_cast(stop,State) ->
     0..|   {stop,State};
        |  handle_cast({storevar,Name,Value}, State = #state{var=D}) -> 
     1..|      NewD= dict:store(Name,Value,D),
     1..|      {noreply, State#state{var=NewD}};
        |  handle_cast({storefunc,Name,Par,Desc,Text}, State = #state{func=F}) -> 
     3..|      NewF= dict:store(Name,{Par,Desc,Text},F),
     3..|      {noreply, State#state{func=NewF}};
        |  handle_cast(Msg, State) -> 
     0..|      io:format("calc_store received cast: ~p~n",[Msg]),
     0..|      {noreply, State}.
        |  
        |  handle_info({'EXIT',_P,shutdown},State) -> 
     0..|      {stop,State};
        |  handle_info(Msg,State) -> 
     0..|      io:format("calc_state received info: ~p~n",[Msg]),
     0..|      {noreply,State}.
        |  
        |  terminate(_Reason, _State) -> 
     0..|      ok.
        |  
        |  code_change(_OldVsn, State, _Extra) -> 
     0..|      {ok, State}.
于 2013-07-10T12:45:27.120 回答