Teaching Unit Testing at a local University College

Teaching Unit Testing at a local University College

Today I had the pleasure of lecturing .NET Unit Testing at YRGO, a local University College in Gothenburg. This was actually the fourth year lecturing at YRGO and it’s something I really enjoy doing next to my “regular” work assignments. This session was based a lot on my session from my CodeGarden talk earlier this year

These students are studying to become Web Developers and the topic was .NET Unit Testing. I think it’s important to teach Unit Testing at an early stage before the students have even graduated so that it becomes a standard from an early stage to write well-tested code. Here are some of the topics we covered during the day:

What is Unit Testing?
Here we talked about what exactly is Unit Testing, why do we need it and what problems does it solve? We also discussed the differences between a Unit Test and an Integration / E2E test (mentioning the Testing Pyramid).

How to get started with Unit Testing
During this part of the session we did a walkthrough of how to set up a new test project and briefly mentioned the different Testing Framework and their differences. We used Visual Studio’s xUnit Test Project as an example to quickly get started but also looked at all the packages installed so everyone understands what happens under the hood when you choose a Test Project template.

Let's write some tests!
This was the main portion of the session where we did a breakdown of the different components and concepts needed to get started testing, as well as actually starting to write our very first tests. This part contained topic such as:

  • Naming Conventions
  • Arrange, Act & Assert
  • Project & Folder structure
  • Different type of Assertions
  • Using the test Runner
  • Setup and Teardown
  • Fluent Assertions
  • Fact vs Theory / InlineData (xUnit)
  • And more..

Digging deeper
This last part of the day was the “advancing” step where we talked about things like Mocking, Faking, Dependency Injection and Test Driven Development (TDD). You could also call this the “melt your brain before we go home”-section. 🤯

Bingo!
The day ended with a concept I’ve done a few times before when hosting this session, called Unit Testing Bingo! We students are presented with a bingo board where each square contains a unit testing task. The goal of the bingo is to complete one full row, or if you are a really fast learner, the entire board. 

There are no winners or losers, it’s just meant as a motivational tool to gamify the learning experience. Also since each task varies by level of difficulty, the students can pick for themselves which tasks they feel that they can complete. An example of a task could be “Create a calculator class with a Multiply method that multiplies two given values and write a test for the output. Extra point if done using TDD.”

Summary
By the end of the day I got the impression that the students enjoyed the day and that Unit Testing no longer feels as scary. This was definitely not the last time teaching this session and I’m hoping I can package the session a bit so it becomes something I can deliver whenever with very little (or none) preparation in the future. To be continued...

Cheers friends! ❤️