One of the hardest things about teaching students about programming is getting them to properly test their code. Testing is something I explain regularly and go over from the very beginning of a course. Every course. And yet, time and again I run student programs myself and find they are not giving the correct answers.
Anyone who has every taught students programming has looked at the results of a student program and asked them “is that the right answer?” and had them reply “I don’t know. I think so.” Students seem to assume that if the program compiles and runs and gives an answer then it must be the right answer. It’s as if they expect magic from the computer sometimes.
One of the very first projects many students see is temperature conversion from Fahrenheit to Celsius. Well at least it is common in the US where we are still using Fahrenheit but our neighbors are using Celsius. Students will plug in random numbers, get an answer and declare “it works.” Now I test that sort of program by using temperatures I know the answer to: boiling and freezing temperatures of water and of course –40 which is the same on both scales. This seldom seems to occur to students though. I wish I knew why but at least it is the basis for a good conversation on test data.
Should I provide test data with expected results for projects? That’s pretty easy for some projects. It’s not as easy for others. I also want students to figure out how to create good test data though and handing out too much test data gets in the way of that. There is also the problem of students hardcoding results into a project. That hasn’t happened in my classes in a long time but I know it does happen.
We’ll be having yet another conversation about testing in my class this week. Perhaps I just need to keep hammering it in. Anyone have any advice for me? I’m open to suggestions.