commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: [lang] Unit test coding conventions?
Date Fri, 05 Jul 2002 17:11:43 GMT

On Fri, 5 Jul 2002 wrote:

> Date: Fri, 5 Jul 2002 12:37:00 +0200
> From:
> Reply-To: Jakarta Commons Developers List <>
> To:
> Subject: [lang] Unit test coding conventions?
> Hello,
> I want to write some additional unit tests for the Strings class as was
> listed in the todo's for an 1.0 release. I looked at the StringsTest class
> and noticed that there are not a lot of test methods, but each of the test
> methods contains multiple assert statements. Personally, I don't like this
> approach, since a test method will fail on the first failing assertion. The
> following assertions will not be executed. I would like to have a test
> method for each separate case, which means that you will get a n-1 relation
> between test methods and production code methods.

My personal preference is to go ahead and use a single test method with
multiple asserts in some circumstances -- particularly when you want to
run through a sequence of tightly related states where it would be tedious
and error-prone to reconstruct each state in individual test methods.  In
a sense, these start to be class-level unit tests rather than method-level
(consider testing a stack class without ensuring that the methods actually
work together), but they are appropriate to include in a low-level test
suite because they are still independent of other classes in most cases.

The "test exit on first fail" problem hasn't really bothered me -- after
all, most of the time all the tests really *do* run successfully, unless
you happen to break something with what you are changing.  In that case, a
little self-inflicted pain (fixing asserts one at a time) is good negative
feedback on breaking things :-).

> How about you?
> Ringo


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message