Erlang Programming/Unit Testing with eunit
Installing eunit
editThis section will show you how to install eunit on different operating systems. Once you have installed eunit its use is fairly consistent across the different operating systems.
ubuntu
editGet source with:
svn co http://svn.process-one.net/contribs/trunk/eunit eunit
Compile code with:
.../eunit$ make
Copy to /usr/lib/erlang/lib
Test the Installation
editTo test that everything is installed ok before writing any tests
create a file test01.erl
with the following contents:
-module(test01).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
Compile this file as follows:
$ erl
> c(test01).
{ok,test01}
If you get the result {ok,test01}
then you've installed eunit correctly.
Using eunit
editWe'll start by writing a passing test and a failing test. In the file you created to check the installation add the following:
passing_test() -> ?assert(true). failing_test() -> ?assert(false).
Run the tests as follows.
Eshell V5.5.5 (abort with ^G) 1> c(test01). {ok,test01} 2> test01:test(). test01:failing_test...*failed* ::error:{assertion_failed,[{module,test01}, {line,29}, {expression,"false"}, {expected,true}, {value,false}]} in function test01:'-failing_test/0-fun-0-'/0 ======================================================= Failed: 1. Aborted: 0. Skipped: 0. Succeeded: 3. error 3>