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

eunit开展单元測試时的方法

2012-12-19 
eunit进行单元測試时的方法1、測試代碼写入头文件件中.主程序中加入-ifdef(TEST).?-include(module_tests.

eunit进行单元測試时的方法

1、測試代碼写入头文件件中.

主程序中加入

-ifdef(TEST).?
-include("module_tests.hrl").?
-endif.?

在module_tests.hrl中写入

-include_lib("eunit/include/eunit.hrl").?

module_test_() ->

?? [?assertEqual(ok, public_function(),

?

?? ??assertEqual(error, private_function())].

2、-compile(export_all)

-ifdef(TEST).

-compile(export_all).

-endif.

然后另写測試Module,进行測試.

?

==============================================

这样写的好处:

产品代碼和測試代碼分开.

产品代碼编译时,可不编译測試代碼.

私有的方法可以进行測試.

单元測試易修改.

?

注:TEST测定可在erlide下,Erlang Compiler中输入{d, 'TEST'}.

热点排行