EUnit: a lightweight unit testing framework for Erlang
Authors: Richard Carlsson, Mickaël Rémond
Venue: Proceedings of the 2006 ACM SIGPLAN workshop on Erlang (2006)

In recent years, agile development methods have become increasingly popular, and although few people seem willing to go all the way with Extreme Programming, it seems that there is a general consensus today that test-driven development with unit testing is a Good Thing. However, this requires that tests are easy to write, since programmers are generally lazy, and that running the tests is easy and quick and the test results are presented in a concise manner, to make the feedback loop as short as possible. Failing this, it is likely that testing will not be extensively used during development.The concept of a lightweight unit testing framework that fulfils these goals, tailored to a particular programming language, was popularized by the JUnit framework for Java, written by Kent Beck and Erich Gamma. This was based on an earlier framework for Smalltalk called SUnit, by Kent Beck. The ideas in JUnit are easily transferred to any other object-oriented language, and today variants have been written for many different programming languages.We will here present our adaptation of these ideas to Erlang. The EUnit framework provides the usual features of such frameworks: writing tests is very easy indeed, and so is running them. Like most other similar frameworks, we rely on program introspection and naming conventions to reduce the amount of coding necessary to write tests. However, there are also some unusual aspects. Since Erlang is functional, rather than object oriented, it is not possible to use inheritance to provide basic test functionality, nor to use object instantiation to handle things like setup/teardown of contexts for tests. Instead, we base our system on a "language" for describing sets of tests, using mainly lists, tuples, and lambda expressions. We also make rather heavy use of preprocessor macros to allow more compact and readable notation. Because test descriptions are data, they can be easily combined, abstracted over, or even be generated on the fly. Lambda expressions allow subtests to be instantiated with setup/teardown contexts.Furthermore, the parallel and distributed nature of the Erlang language on one hand provides a challenge, but on the other hand gives us enormous power and flexibility. For instance, it is trivial to express in our test description language that a set of tests should be executed by a separate process, or on a specific machine, or all in parallel, or even as a number of subsets of parallel tests, with each subset running on a separate machine. Apart from providing easy distributed job control, this allows us to write unit tests that test the behaviour of parallel and distributed programs, something which otherwise tends to require so much coding for each test as to be impractical.Although EUnit is still under development, we feel that it has great potential, and that it uses some novel ideas that could be used to implement similar frameworks in other functional languages. EUnit is free software under the GNU Lesser General Public License. It has not yet been publicly released as of this writing.