yequari.com

Testing Code

When I was in college studying computer science, something that got drilled into me was the concept of test-driven design, or TDD. TDD is a method of designing software in which you write your test cases first, then go and write your code. The advantage of doing this is that you make a sort of checklist of items to complete, which you can periodically test your code against to measure your progress and verify that changes to your code don’t break any previously working tests. This usually all depends on having some testing framework installed, either as an included component of the language, or as a third party library. In school we would use JUnit since a lot of the mid-level classes were taught in Java.

While it all sounds great in theory, in practice it was difficult to implement. Almost everyone would write their code first and the test cases would came later, usually as an afterthought, because part of the assignment grades would be checking test coverage. Why is that? I think everyone can agree testing code is important, or else my peers and I would not have spent hours manually testing our assignments, but when presented with the knowledge that this could all be automated, why did we not jump at the opportunity?

Don’t test all at once, start with 1 good testcase and 1 bad testcase, build out from there.

Tags: