O'Reilly logo

Erlang Programming by Francesco Cesarini, Simon Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

EUnit

EUnit provides a framework for defining and executing unit tests, which test that a particular program unit—in Erlang, a function or collection of functions—behaves as expected. The framework gives a representation of tests of a variety of different kinds, and a set of macros which simplify the way EUnit tests can be written.

For a function without side effects, a test will typically look at whether the input/output behavior is as expected. Additionally, it may test whether the function raises an exception (only) when required.

Functions that have side effects require a more complex infrastructure. Side effects include operations that might affect persistent data structures such as ETS or Dets tables, or indeed operating system structures such as files and I/O, as well as operations that contain message passing among concurrent processes. The infrastructure needed to test these programs includes the following:

  • Testing side-effecting programs typically requires some setup and initial modification of the data before checking the behavior of a particular operation. This needs to be followed by a cleanup of the program state.

  • Testing units within a concurrent program typically requires a test rig in which some mock objects or stubs are written to stand in the place of other components expected to interact with the unit under test.

EUnit supports testing side-effecting and concurrent programs. Let’s start with the simplest case of functional testing.

How to Use EUnit

EUnit provides a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required