Saturday, April 19, 2014

Getting Started Testing

PyCon US 2014, Ned Batchelder

If you've never written tests before, you probably know you should, but view the whole process as a bureaucratic paperwork nightmare to check off on your ready-to-ship checklist. This is the wrong way to approach testing. Tests are a solution to a problem that is important to you: does my code work? I'll show how Python tests are written, and why.



-- I've heard it's said DRY doesn't apply to testing, when I see my coworker just cut and paste one test to the next and I go back and something changes with the test, it feels like it should be dry?
-- That's silly, yeah! I have no idea why people say DRY should not apply to testing. Testing is one of those mysterious worlds where you'll find experts and they will say things to you (not me, I can be trusted, but the other ones who will say these mysterious things :) and you believe them because testing is mysterious, but maybe they are wrong.
-- Well, I mean in one case where it makes sense to me is that once you start making your tests DRY your tests become more complex and then you have to test your tests.
-- Yeah, you do. I know why they say they should not be DRY, because some people like tests sort almost documentation of how things should work and they like a test case be completely self-contained. But if that means that the same 10 lines setting up the same fixture you are going to use in sixty tests that just seems silly to me.

No comments:

Post a Comment