Validation routines as an intro to unit testing
For the past several weeks I’ve been introducing TDD and a focus on unit testing at work to the TA group. Well I introduced it months ago but am now just convincing (forcing) people to do it. This can be an imposing subject for people that have spent their entire careers scripting inside of Maya. I think I’ve finally figured out the easiest way to ease people into TDD and unit testing in a way that is both easy to do and demonstrates immediate benefit (and in fact done it successfully with two people already).
Writing data/content validation.
Writing validation routines for data follows the TDD paradigms to a T. You just need to explain to people how to write the tests first, and then run those tests from their IDE. So instead of writing some complex function filled with if checks that tests for different things and needs to be commented to explain all the things it tests for and is constantly breaking, you just write your battery of tests for valid and invalid content. Then you run them, and keep improving your validation method(s) until the tests pass. Then, in true TDD style, only go and refactor the validation code itself if you need it- with confidence you aren’t breaking things. And then when you think of more things to validate, you add more tests, with no risk of regression.
TDD is tailor made for data/content validation.
Walk them through the first few tests yourself to get them set up, then have them write the rest of the tests for a validation routine. It will also be very clear if they ‘get it’ or not.
Once they get it, there are some other areas that TDD can be applied to with almost as much ease that I’ll go over next time.