erlang的单元测试工具 Eunit
详细,click here
%% Author: John %% Created: 2010-7-19 %% Description: TODO: Add description to fit -module(fit). %% %% Include files %% -define(EUNIT, true). -ifdef(EUNIT). -include_lib("eunit/include/eunit.hrl"). -endif. %% %% Exported Functions %% -export([fib/1]). %% %% API Functions %% fib(0) -> 1; fib(1) -> 1; fib(N) when N > 1 -> fib(N-1) + fib(N-2). %% %% Local Functions %% %% test -ifdef(EUNIT). fib_test() -> fib(0) == 1. fib_test_() -> [?_assert(fib(0) == 1), ?_assert(fib(1) == 1), ?_assert(fib(2) == 2), ?_assert(fib(3) == 3), ?_assert(fib(4) == 5), ?_assert(fib(5) == 8), ?_assertException(error, function_clause, fib(-1)), ?_assert(fib(31) == 2178309) ]. -endif. %% setup() -> %% io:format("Setup called", []). %% %% do_test_() -> %% {setup, fun setup/0, [?_assert(1=:=1)]}. |
如何测试:
erl
1> fit:test().
All 9 tests passed.
ok
2>