Data-driven testing

andrew cooke andrew at acooke.org
Wed Apr 23 10:39:45 EDT 2003


this isn't an exact solution, but maybe it will help you.  i had a similar
problem while writing a parser.  in that case i wanted to test parse
trees, but didn't want to specify the whole tree by hand for each test
case.  what i did was develop a simple specification "language" that would
check against only the sub-tree that i was interested in, allowing other
sub-trees to be excluded.

for example:

    compare("p1|p2",
            "<ASTPatternNT>"+
            "<ASTLocationPathPatternNT>...</ASTLocationPathPatternNT>"+
            "<ASTLocationPathPatternNT>...</ASTLocationPathPatternNT>"+
            "</ASTPatternNT>",
            COMPLETE);

this specifies that the description is for the whole tree (COMPLETE), but
that sub-nodes of ASTLocationPathPatternNT are not checked ("p1|p2" is the
xpath statement that needs to be parsed).

or:

    compare("id(' a'  )",
            "<ASTIdT getToken=' a'/>",
            FRAGMENT);

which specifies only that an Id token exists with the correct name
somewhere in the tree (i even checked my whitespace handling ;o).

andrew

ps this code is all in java, i'm afraid - it can be downloaded from my web
site (see sig)


aahz at pythoncraft.com said:

> As I just mentioned in another post, I'm writing an ASCII database for
> my address book.  Actually, the main reason for writing it was because
> I've been maintaining multiple lists for various kinds of party invites,
> and the update problem was killing me.
>
> While writing it, it occurred to me that I *ought* to be using unit
> tests to make sure that it was working correctly, but two things stopped
> me.  Secondly, I was in a hurry.
>
> But firstly, I ran into the same problem I had when writing the BCD
> module: how the heck does one write tests when the results are
> hand-calculated?  There were several times when I wrote what I thought
> were correct tests for the BCD module, and my code was right and my test
> was wrong.
>
> In the case of my ASCII database, I'm going to need a big matrix to
> properly test the query language.  How do I build that matrix?


-- 
http://www.acooke.org/andrew





More information about the Python-list mailing list