Re: unit testing C++ code from perl
- From: "Nick Keighley" <nick_keighley_nospam@xxxxxxxxxxx>
- Date: 6 Jul 2006 05:08:25 -0700
Phlip wrote:
I owe Noel a review. Naturally, he used my TEST() macro (which I got from
CppUnitLite), but it doesn't have the ability to inherit suites, hence to
setUp or tearDown.
My bad - I didn't see TEST_FIXTURE() yet. The system appears to use a
fixture's constructor and destructor as setUp and tearDown, which has a few
reasons to be the correct idiom in C++.
do you have to read a book to understand any of this? Are there
standard names
for macros(?) used in TDD? Are we supposed to just *know* what TEST or
TEST_FIXTURE does?
To write a general purpose library intended for a wide audience with
*any*
examples of usage or explanation of what the various parts do, just
seems
bizzare to me!
Yes, I could puzzle it all out. But the temptation is to use the same
time to
write my own.
----8<--------------------------
TDDers:
My former colleagues, Noel Llopis and Charles Nicholson, have
published a nice little C++ test rig, easily competitive with
CppUnitLite. It features the Test Collector pattern via the TEST()
macro, exceptions caught directly in the CHECK*() macros, and a
healthy streaming output system.
obviously to practice TDD you need a vocabulary transplant.
It is within a few features of what I always demand of my C++ test
rigs. I severely influenced Noel's shop's prior test rig (uncredited).
So understand, while I have fun, there's a little history involved
here.
* As a cheap shot, the name is wrong. Developer-centric
testing and strict "Unit Testing" is orthogonal.
Sometimes they are the same and sometimes not. The
failure of a Unit Test implicates only one Unit in the
source code. Developers don't need such rigor as they
run their tests over and over again, so failure should
only implicate the most recent edit. All *Units have
this problem...
* the top-level Makefile should have a make test target.
* the README file needs a "getting started" section. The
"examples" are, naturally, the self-tests.
ah. :-)
* the Win32 side should use OutputDebugString(), to flow
the test results into the Output panel of a Win32 IDE.
* CHECK*() failure might not invoke a breakpoint. Test
rigs should breakpoint on such errors, with __asm { int
3 } or the equivalent, and then they should present the
option to continue running. This is primarily to ensure
a new test fails for the correct reason.
* The test runner could use a ... progress bar.
* A CHECK*() failure's diagnostic should use the format
"filename:99: error" on GNU, and "filename(99): error"
on Win32, so an IDE can navigate instantly to such
faults.
* The test suite system, TEST_FIXTURE(), might not support
the Abstract Test pattern. That simplifies testing
aspects of the Liskov Substitution Principle.
There's still plenty of good news. For example, CHECK_EQUAL(), despite
being a macro, only evaluates its arguments once. Mine does to, but
Noel and Charles have complete unit tests on all these things.
The code is generally exemplary, with tiny functions, no comments,
what! Its *good* to have no comments?! Not even a one liner saying what
it's
*for*?
and
few dependencies. Some test rigs (such as CppUnit) go crazy "coddling"
errors - making formatted lists of them, and such. Pure TDD only needs
instant attention for the most recent errors, and UnitTest++ has only
gentle support for making lists of them.
Noel is the author of /C++ for Game Programmers/, where he comes down
hard on the crufty side of huge C++ projects, including macro abuse. I
wish I could accurately describe his reaction when I first introduced
him to the TEST() macro. It's nice to see he has recovered enough to
promote it!
----8<--------------------------
Someone suggested I post this to their mailing list. I will if my search for
one more specific technical problem succeeds.
--
Nick Keighley
.
- Follow-Ups:
- Re: unit testing C++ code from perl
- From: Phlip
- Re: unit testing C++ code from perl
- From: Phlip
- Re: unit testing C++ code from perl
- References:
- Re: unit testing C++ code from perl
- From: Tom Plunket
- Re: unit testing C++ code from perl
- From: Nick Keighley
- Re: unit testing C++ code from perl
- From: Phlip
- Re: unit testing C++ code from perl
- From: Phlip
- Re: unit testing C++ code from perl
- Prev by Date: Re: question
- Next by Date: Re: Program Request
- Previous by thread: Re: unit testing C++ code from perl
- Next by thread: Re: unit testing C++ code from perl
- Index(es):
Relevant Pages
|