Test-Driven Development in CS Education
Hello, I am a relatively new CS professor. I have noticed that my students are, for the most part, very bad at testing their programs. They generally only test the very baseline of functionality required for a project. In software engineering, we briefly cover test-driven development, but it seems to be way too late at that stage. I have begun introducing the idea of testing in earlier courses and ask students to submit tests along with their code for 1 or 2 assignments.
What are other people's thoughts on this? Should we teach good software testing earlier?
Posted Oct 12, 2012, 3:26 PM UTC
33
There's been some research on TDD, largely finding that students aren't very receptive to it. E.g.:
It's worth noting that these same sources say that TDD is absolutely beneficial when the students actually use it! It's rather like commenting and broccoli- they may not like it, but it's still good for them.
I'll elaborate a bit that generally students see value in TDD and will write tests when it is part of the assignment. However, there is notable resistance to strictly follow the "test-first" principle. Consequently, they tend to adopt development patterns that somewhat resemble TDD.
Writing unit tests is not particularly difficult so it should not be out of the reach of novice programmers. In addition, I'd argue that writing unit tests encourages reflection over requirements and critical analysis of special cases, which are meaningful skills to develop as budding computer scientists. We regularly teach TDD in both our CS1 and CS2 classes.