A first glance at teaching TDD for university students

Published May 23, 2025

The content here is under the Attribution 4.0 International (CC BY 4.0) license

Recently I have had an opportunity to teach Test-Driven Development (TDD) to university students, and I wanted to share my initial thoughts and experiences. This post will provide a brief overview of the challenges I faced, the strategies I employed, and the insights I gained while introducing TDD to students who were new to this methodology.

Introduction

Teaching TDD to university students presents unique challenges, especially when they are not familiar with the concept of writing tests before code. The initial resistance to the idea of writing tests first can be a significant hurdle. However, I found that with the right approach, students can quickly grasp the benefits of TDD and start applying it effectively.

At first, students were skeptical about the value of writing tests before writing code. They often questioned why they should invest time in writing tests when they could simply write the code directly. To address this, I emphasized the long-term benefits of TDD, such as improved code quality, easier debugging, and better maintainability. From the start, it seems that some of them already had the conception that TDD was just for backend development.

I often use the example with code first and then theory later. This is some inherited knowledge from (Fowler, 2018) that employed the moves done in the code first then showed the theory behind it. This approach helps students see the practical application of TDD in real-world scenarios, making it easier for them to understand its value.

Kata

To introduce TDD to students, I started with a simple kata that they could relate to. The kata involved implementing the famous fizzbuzz problem, which is a common exercise in programming courses. The students were asked to write tests for the fizzbuzz function before implementing the actual code. This hands-on approach allowed them to experience TDD firsthand and see how it can lead to cleaner and more reliable code.

The fizzbuzz kata was a great starting point because it is simple enough for beginners to grasp, yet it still requires them to think critically about how to structure their tests and code. As they worked through the kata, I encouraged them to focus on writing small, incremental tests that would guide their implementation.

Challenges

After that, it was their turn to give a try with TDD but now with another kata named Simple Calculator. I personally had to adapt to students approach on the technological tech stack, as some of them used python, some used typescript, some java and others c#.

This diversity in programming languages presented a challenge, as I had to ensure that the TDD principles I was teaching were applicable across different languages and frameworks. However, I found that the core concepts of TDD remained consistent, regardless of the language used. This allowed me to focus on teaching the fundamental principles of TDD while also addressing language-specific nuances.

Reflections

Out of the box, students perceived the benefit of thinking about the code, followed with a instant happiness when something failed that they didn’t antecipated. This was a great moment to show them that TDD is not just about writing tests, but also about thinking critically about the code they are writing. It was rewarding to see them embrace the TDD mindset and start applying it in their own projects. Overall, teaching TDD to university students has been a rewarding experience. While there were challenges along the way, the students’ enthusiasm and willingness to learn made it all worthwhile. I look forward to continuing to explore TDD with them and helping them develop their skills as software developers.

Some of them, had questions that were towards pros/cons about using assertions in a single test method, others questioned how to tackle the naming of the testing and other just started to generalize the test case using loops from the start.

Practices around TDD

Such discussions led me to refer xUnit (Meszaros, 2007) and TDD by example (Beck, 2000), which provides a comprehensive overview of TDD principles and practices. I also shared resources on best practices for writing effective tests, such as the importance of clear naming conventions and the use of assertions to validate expected outcomes.

References

  1. Fowler, M. (2018). Refactoring: improving the design of existing code. Addison-Wesley Professional.
  2. Meszaros, G. (2007). xUnit test patterns: Refactoring test code. Pearson Education.
  3. Beck, K. (2000). TDD by example. Addison-Wesley Professional.

You also might like