directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vincent Tence <>
Subject Re: Tests naming
Date Wed, 16 Mar 2005 18:19:54 GMT
> Tencé, Vincent wrote:

> I agree to a certain extent, although tracability back to the method we
> are testing is helpful to me.
> I tend to favor a variation on what you do.  I use the method name
> followed by descriptions.
> For a method named "loadClass" I would do something like this:
> testLoadClass() // normal critical path
> testLoadClass_fromCacheIfScriptNotChanged()
> testLoadClass_noClassNameProvided()
> testLoadClass_reloadIfScriptChanged()
> Each testing a different specific aspect of the method.  I will have a
> different test for each permutation
> or branch I have to ensure works properly.  If there are branches I
> can't excersize from the test harness
> then it is dead code and needs to be removed.  The approach I use gives
> both the tracability to the
> method and the clarity you desire.  Just my 2 cents.

The intention is good, but I have some concerns with this approach.

I like to think that the objective of a test is not to test a method, but
a behavior of the code under test. This is important as it is reflected
directly in the test name. In your example, it's hard to tell what you
want to ensure with testLoadClass_noClassNameProvided(). What is intention
of the test? What is the expected behavior. Same with testLoadClass().
What is the normal path supposed to do?

I consider tests a powerful documentation mechanism, and naming your test
methods according to the intention of the test help document how the code
behaves, what its feature set is.

Moreover, when doing TDD, you usually start with a feature to implement at
the class level, e.g classes are reloaded if script file was changed. You
don't know at this point what the method name will be like. What you know
though (at least I hope ;-)) is what you're trying to achieve. Design and
interfaces will emerge as your driving from your tests.

My own 2 cents :)

-- Vincent

View raw message