首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

利用EUnit兑现代码覆盖

2012-12-18 
利用EUnit实现代码覆盖实现代码覆盖关键在于erlang中cover,他的实现机制是对module进行再编译,实际上就是

利用EUnit实现代码覆盖
实现代码覆盖关键在于erlang中cover,他的实现机制是对module进行再编译,实际上就是加上了自己的統計方法.然后通过cover:analyse(Module)返回統計結果.

一个简单例子:
利用EUnit进行自动化測試,以unit_start为例:
-module(eunit_start).
-include_lib("eunit/include/eunit.hrl").
reverse_test() -> ?assert(1 + 1 =:= 2).
执行:
cover:compile(unit_start),
unit_start:test(),
cover:analyse_to_file(unit_start,"unit_start.html",[html]).
在unit_start.html中就会看到每行代碼执行的次数.

热点排行