Test-driven Pyweek
Since the last Pyweek I've become seriously disciplined at test-driven development in my day job. If it doesn't has tests, how can I know it works? Now I'm wondering whether it would be valuable for Pyweek.Six months ago I would have thought it was a crazy idea to write tests for a Pyweek game. Pyweek is all about coding as fast as possible, right? And tests are just a waste of time I could be spending adding more features! But seriously, the amount of time I spend in a Pyweek manually testing my own game is massive, and it's always possible to leave some crasher in, something that worked once but got broken in the headlong rush to move features. I've read articles suggesting TDD is just always faster.
And anyway, how can you test that such and such a particle effect looks just so? Well, you're much more likely to break the code so that the particle effect just crashes with some exception, or is never started, or emits them off screen or something. How it looks is hard to test, but it's not the most important thing to test. I love having to not have to deal with that kind of crap any more.
So what do we think? Has anyone done a substantial amount of TDD in a Pyweek? Is it an approach that can work?
(log in to comment)
Comments
I usually code alone but when I don't [insert meme here], I partition the code in such a way that all coders don't really have to touch anyone else's code with the exception of one or two functions. One of the biggest payouts of unit testing is a safeguard of one coder violating the assumptions of code they didn't write but in isolated coding, this doesn't have as much value.
And for everything else, there's good ol' fashioned black-box manual testing which usually is far more efficient for the "particle effect looks sorta funny" class of bugs.
The difficulty with full TDD for games is writing acceptance/functional/system tests (they all mean the same thing, to me) which verify the end-to-end behaviour of the whole system. For example, writing a test which fires up your game and 'plays' it, walking the whole things through to game completion. (or a series of such tests, one for each level, or however else you choose to partition it.)
Without such a system-level test, you aren't doing proper TDD, and obviously writing such a test, in the general case, is difficult, because it requires the test to look at the screen and analyse the bitmap currently being displayed, and then decide on what inputs to provide. For some games (e.g. roguelikes) this is relatively easy, for others (e.g. openGL FPS) this is considerably harder.
Aside from that caveat, doing semi-TDD (just using unit tests) will, IMHO, be faster & produce better designed & implemented code than not using TDD, provided you have experience working in a TDD style.
I think all you can usefully do for particle effects is have unit tests which assert that you end up calling your rendering API with the correct parameters. If these tests are somewhat immune to changes in values of constants like colors, "density", etc, then you can tweak the appearance somewhat without breaking all the tests.
I disagree. I don't think there's anything about TDD that mandates that tests must cover every level of abstraction. It's just about writing tests first to verify that what you are about to write will be correct. TDD is valuable whatever the level of tests you write
I don't think it'll give you any benefit, except possibly learning about techniques for auto-testing games. At least it won't make your PyWeek game get done any sooner.
Mark
However, for the algorithmic stuff, it's been very useful - got some complicated stuff working really very fast.
bjorn on 2012/04/26 00:08:
I did a bit of tdd during pyweek a couple years ago, but was part of a team and not everyone was writing unit tests, and the code moves so quickly that keeping the tests up to date and relevant was pretty fruitless and I abandoned it pretty quickly.But if you are comfortable with tdd and are the only one working on the code (or everyone on your team is doing TDD) then I say go for it. I've heard estimates that it usually takes about 3 weeks on a new project before TDD starts paying off and being faster than writing the code with no tests, so pyweek may not be a prime candidate for that here, but it probably depends what you are comfortable with, and it really can save you a lot of debugging so I say go for it. I'd be interested to hear how it goes.
If I find time to participate this time, there are definately pieces I would TDD, and others I'd probably just hack away at to get the feel and look right.