[erlang-questions] Unit testing code - whence?

Jon Watte jwatte@REDACTED
Wed Jul 6 21:32:41 CEST 2011


Actually, test driven development methodology has a very clear separation
between these:
- acceptance tests / interface tests use only the public, exported interface
of a component/system/unit, and tests it in a "clean room" environment.
- unit tests grope around the internals of your unit in a way that nobody on
the outside can. It's used to verify implementation details of the unit that
may be important to the implementation, but not to anyone on the outside.

There is a little bit of religion in this -- some people tend to feel very
strongly that only acceptance tests matter. Personally, I find unit tests to
be useful in many cases, especially when growing an implementation using
testing in the first place.

For example: You might want to test a gen_server. This gen_server uses a
state record that is internal to the module. A unit test, inside the module,
can set up a state record, and then call handle_call() directly, making sure
that particular implementation details do what they're supposed to.
Meanwhile, nobody outside the module should ever call that function (except
for the gen_server itself, of course), and any test on the outside should
only use the public interface functions.

Sincerely,

jw


--
Americans might object: there is no way we would sacrifice our living
standards for the benefit of people in the rest of the world. Nevertheless,
whether we get there willingly or not, we shall soon have lower consumption
rates, because our present rates are unsustainable.



On Tue, Jul 5, 2011 at 10:56 PM, Gianfranco Alongi <
gianfranco.alongi@REDACTED> wrote:

> I disagree.
> Putting your tests in another module will actually force you to think more
> of your design, making the application/lib more testable without being
> necessarily more "open". Another huge win is that you will have a cleaner
> implementation module. And you will be able to easily mix and match
> revisions of code and tests. /G
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110706/15089ba5/attachment.htm>


More information about the erlang-questions mailing list