< Erlang Programming
Installing eunit
This 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
Get 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
To 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
We'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>
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.