[TIP] Docstrings in Test methods
gary.bernhardt at gmail.com
Sun Nov 6 12:01:22 PST 2011
On Sat, Nov 5, 2011 at 10:21 PM, Alfredo Deza <alfredodeza at gmail.com> wrote:
> Not sure I entirely agree with this approach, it could get very
> repetitive very fast. I tend
> to have test classes that I can group with a setup that makes sense
> for a few tests, if I name
> the classes after the state I would have to probably use inheritance
> to avoid repeating setup
> over and over again.
Exactly: the test class's name refers to the state of the world that
the test expects. That world is created in the setup. These things
aren't in opposition; they're the same!
It's true that this can lead to inheritance, but that's because the
popular Python test runners are still clones of SUnit as it existed in
1994. RSpec's nested contexts solve this problem without confusing
Though, with that said, nested contexts and inheritance in test
classes are often indications that your design can be improved. If
there are two ways in which the world can vary, both of which are
complex enough to justify multiple tests, you're usually better off
splitting the class under test.
More information about the testing-in-python