unit test strategy
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Sep 16 03:42:09 EDT 2012
On Fri, 14 Sep 2012 19:59:29 -0700, Aaron Brady wrote:
> Hello,
>
> I've developing a test script. There's a lot of repetition. I want to
> introduce a strategy for approaching it, but I don't want the program to
> be discredited because of the test script.
Test scripts should be simple enough that they don't require test scripts
of their own. Or at least, not too many "test-the-test" tests. It is
possible to avoid repetition without making convoluted, hard to
understand code. Based on the tiny code fragments you give below, I
suspect that your test script will need more testing than the code it
tests!
> Therefore, I'd like to know
> what people's reactions to and thoughts about it are.
I'd love to make some suggestions, but I have *no idea* what you are
talking about. See further comments below:
> The first strategy I used created an iterator and advanced it between
> each step:
What are you using an iterator for? What does this have to do with unit
testing?
So far, your explanation is rather lacking. It's a bit like:
"I want to create an alarm system for my home, so I put in a screw and
tightened it after each step."
Doesn't really help us understand what you are doing.
> self.op_chain(range(5), ('add', 5))
> self.op_chain(range(5), ('add', -2), ('add', -1))
> self.op_chain(range(5), ('discard', -1), ('add', 5))
> self.op_chain_ok(range(5), ('update', [0, 1]))
> Etc.
Where is the iterator you created? Where are you advancing it? What's
op_chain do?
> I'm considering something more complicated. 'iN' creates iterator N,
> 'nN' advances iterator N, an exception calls 'assertRaises', and the
> rest are function calls.
[...]
You've proven that even in Python people can write obfuscated code.
> Do you think the 2nd version is legible?
Neither version is even close to legible.
> Could it interfere with the accuracy of the test?
Who knows? I have no clue what your code is doing, it could be doing
*anything*.
--
Steven
More information about the Python-list
mailing list