From Zero to Hero: Writing Testable Code in C#

Learn how to write testable C# code using modern coding practices

About This Course

Everyone knows by now that testing is a mandatory part of software development, but it's very easy to make it hard for yourself to write tests for the code you just wrote. Writing testable code is a craft practised by the most seasoned software engineers, and it is usually a sign of a clean codebase that uses modern practices. Nowadays, it is pretty easy to use AI coding assistants to write tests for you, but true engineers develop a deep understanding of how you can write testable code. In this course, Gui Ferreira will walk you through why writing testable code using C# is so important and show you step-by-step how you can learn this art and follow it for the code you write.

Course Curriculum

4h 30m 8 sections
Welcome
01:32 Free preview
What will you learn in this course?
03:05 Free preview
Who is the course for and prerequisites
00:57 Free preview
The Cost of Untestable Code
05:49
What makes Code "Testable Code"
08:53
What is Unit Testing
02:52
How to approach Testable Code
06:37
Introduction
02:51
Clear Inputs and Outputs
14:03
Explicit Error Handling
11:18
Separation of Construction and Logic
07:56
Visible State Changes
05:38
Exercise
03:09
Section Recap
00:54
Introduction
03:58
Identifying and Extracting Responsibilities
10:09
Dealing with Constructor Bloat
08:07
Creating Effective Injection Points
13:34
Injectable vs. Newable Objects
05:54
Composition of Narrow Components
11:11
Exercise
02:48
Section Recap
01:24
Introduction
04:58
Working with Static Dependencies
09:13
Breaking Dependency Chains
08:39
Creating Abstractions for External Services
08:25
Isolating Framework Code
06:31
Exercise
01:46
Section Recap
02:06
Introduction
07:21
Avoiding Test Interference
10:04
Converting Static Dependencies to Testable Code
06:56
Implementing Pure Functions
00:00
Replacing Traditional Singletons
06:11
Exercise
01:21
Section Recap
01:33
Introduction
01:12
Writing Testable ASP.NET Core Controllers
15:08
Designing Entity Framework Code for Testability
09:22
Making Time-Dependent Code Testable
05:33
Creating Testable External Dependencies
11:56
Implementing Testable Authentication and Authorization
05:35
Section Recap
02:30
Conclusion
01:10

Meet Your Instructor

Gui Ferreira

Gui Ferreira

Guilherme Ferreira, also known as Gui, is a Minimalist Software Craftsman, passionate about simplicity and continuous learning. Gui is a Microsoft MVP for Developer Technologies, a Tech Speaker, a YouTuber, and a .NET content creator. With over 15 years of experience in software development, Gui went from Startups to Tech Giants. Along his journey, he got to know several hats, including Software Engineer, Architect, CTO, and Developer Advocate, gathering a diverse and invaluable skill set.

View all courses by Gui Ferreira

What's New

Deep Dive: Solution Architecture
course

Deep Dive: Solution Architecture

Master solution architecture and turn business needs into scalable, maintainable systems.

Learn More
Migrating: ASP.NET Web APIs to ASP.NET Core
course

Migrating: ASP.NET Web APIs to ASP.NET Core

A step-by-step process to migrate ASP.NET Web APIs from .NET Framework to ASP.NET Core.

Learn More
Getting Started: Caching in .NET
course

Getting Started: Caching in .NET

Let's make the hardest thing in programming easy for .NET software engineers.

Learn More
From Zero to Hero: Testing with xUnit in C#
course

From Zero to Hero: Testing with xUnit in C#

Learn how to test any codebase in .NET with the latest version of xUnit, the industry-standard testing library.

Learn More
Create a ChatGPT Console AI Chatbot in C#
blog

Create a ChatGPT Console AI Chatbot in C#

This walkthrough is your hands-on entry point to create a basic C# console application that talks to ChatGPT using the OpenAI API.

Learn More