Erlang Programming/Unit Testing with eunit

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

Installing eunit[edit | edit source]

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[edit | edit source]

Get source with:

    svn co eunit

Compile code with:

    .../eunit$ make

Copy to /usr/lib/erlang/lib

Test the Installation[edit | edit source]

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 | edit source]

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.