Erlang Programming/Unit Testing with eunit

From Wikibooks, open books for an open world
Jump to: navigation, search

Installing eunit[edit]

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.


Get source with:

   svn co eunit

Compile code with:

   .../eunit$ make

Copy to /usr/lib/erlang/lib

Test the Installation[edit]

To test that everything is installed ok before writing any tests create a file test01.erl with the following contents:


Compile this file as follows:

 $ erl
 > c(test01).

If you get the result {ok,test01} then you've installed eunit correctly.

Using eunit[edit]

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).
2> test01:test().
  in function test01:'-failing_test/0-fun-0-'/0

  Failed: 1.  Aborted: 0.  Skipped: 0.  Succeeded: 3.