On Tuesday, I told the lab of first years I TA that they were going to test their code.
Then one of them started asking me about a quiz.
Erm? No clue. So I said, no we’re going to test your code. And he talks about a quiz some more. It’s all very confusing, but eventually I (helped by several students who joined in) managed to explain that there is a test suite that’s been coded which is going to run their code and see if it works.
OK, these are first years. But in the graduate course I’m taking on testing, I’ve been baffled by the blank incomprehension of graduate students about the concept of testing their code. Bored by the step by step basic instructions the prof is giving. Horrified by the questions that ensue – this level of detail is clearly necessary.
Even more horrified by comments outside the classroom, “I don’t need to know how to test my code, I don’t intend to be a software engineer”. Another guy told me that he had no clue about testing code until his boss asked him to do it one day, saying “someone has to”.
What I told my students: You have to test your code, no-one is that good. People who think they don’t need to test their code are stupid.
In this same lab, I misunderstood part of the specification of the assignment. What made it clear? The test suite. Code is invariably clearer than prose. The test suite is your specification.
I’ve lost count of the number of times I’ve heard “My [Masters/PhD] took [time frame – no less than 6 months] longer because I had to work with this guy’s terrible code”.
Oh really? Did they not test? Did they not document? How about you, though? Are you testing? Are you documenting?
Once you eventually graduate and pass the project on to someone else, will someone be complaining about your code?
We need to test. We need to document. This should not be a question any more, and honestly, I don’t understand why it is! Even if you don’t want to be a software engineer, if you’re going to write code you should know how to test it.
I know, there are no rewards for testing in graduate school. Apart from – better code that it’s easier to do stuff with. And I know, time can be an issue and refusing to deliver to your supervisor because you need to run tests probably won’t go down well, but let’s at least be aware of what the ideal to live up to is, and why, rather than just writing it off as a waste of time.
So even if you don’t buy in to test-driven-development, here’s a suggestion:
The next time your code is broken, don’t debug – test. The next time you are given code that makes no sense, don’t debug – test. The next time you want to complain about the code you’re working with, don’t complain – test. If the tests fail, you’ve proven their code sucks. Good for you. Now you can do better.
Incidentally, the class, although dull, has not been a complete waste of time – in JUnit 4 you can have parametrized tests. Awesome!