Thursday, 26 March 2015

Unit Tests: Before and After

After learning, and re-learning, that the best way to write a sophisticated program is to do extensive algorithmic planning before even looking at an IDE I have decided to take a novel approach to Assignment 3: Writing unit tests before implementing my classes.

This does a few things. First off, it familiarizes me with how class will be structured before I start implementing it. I get to think about what kinds of properties and methods it needs, but I am still a safety-layer away from actual implementation code. I am therefore thinking about what my class needs to do, as well as (to a helpful degree) how it will do it in a way that baby steps me towards filling in the details. Then, when I actually begin to implement my class, I will be productively haunted by the test cases so that I proceed gently and carefully, bearing in mind the totality of what criteria my code must meet for the client. Rushing to patch up a bug with code that creates three more bugs should be more difficult.

Second off, when my class is fully implemented I will have test cases ready to go. This allows me to test my class while implementation details are still fresh in memory, instead of diverting attention to creating Unit Tests (which may reveal things that cause me to actually redesign my class) and then trying to find bugs in code that I have a vaguer recollection of. Furthermore, with general tests cases in place, I can change code to address bugs while still having firm criteria in place for when my class is back to regular performance. At this point I can even design more savvy test cases to find specific bugs, while remaining assured that I know what my code must do before it gets shipped.



No comments:

Post a Comment