Erlang Thesis projects finally online!

Dominic Williams <>
Fri Jul 1 15:39:29 CEST 2005

Erlang Training and Consulting wrote:

 > Test Driven Development In Erlang

When I started using Erlang a couple of years ago, I
had been using Extreme Programming and TDD for 4 years,
so I naturally kept using TDD with Erlang. I actually
found Erlang to be ideally suited to TDD.

So, I was very interested to read that paper, and the
conclusion is interesting (and satisfying for someone
with my bias!) I have a question, and a couple of

1) I don't understand how you measured the number of
faults found in the test-first code. The article says
that you define a fault to be a failure of the
predefined test cases, but the whole point of TDD is to
write code that passes the tests.

2) The test provided in Appendix A is not typical of
TDD tests, because it doesn't test anything. It just
calls some functions, and asserts that they return
ok. If I were working in TDD, I would make that test
pass in 30 seconds and 3 lines of code:

new_company(_,_,_,_) -> ok.
new_site(_,_,_,_,_,_) -> ok.
new_certificate(_,_,_,_,_,_,_) -> ok.

Now, I would have to improve the tests to force me to
write code that is more useful.

3) Test driven development is not (only) about testing,
it is about design. The article incorrectly states that
in TDD, one creates a design then writes tests. The
technique is actually to let the need to write tests
influence the design, and also not to aim at a
definitive design immediately, but on the contrary to
write tests gradually, code the simplest thing that
will pass the tests so far, then add tests and evolve
the design.

So, another angle on the question "is TDD appropriate
for Erlang" is "does TDD encourage good Erlang
design". My experience is that it does:

- it encourages writing side-effect free code, because
it's the easiest thing to test.

- when side-effects are needed, it encourages writing
higher-order side-effect-free functions that do most of
the complex stuff, and take the side-effect producing
code as arguments.

- there is a very natural fit between pattern matching
and adding increasingly complex test cases.

Be that as it may, thanks for the interesting research,
and long live the Erlang/TDD combination!


Dominic Williams


More information about the erlang-questions mailing list