30% OFF - Use code HANDSON30 for 30% off any course or Dometrain Pro! Browse courses →
  • Courses
  • Learning Paths
  • Blogs
  • Authors
  • Leaderboard
  • Dometrain Pro
  • Shopping Basket

    Your basket is empty

  • Business Portal
  • From Zero to Hero: Unit testing for C# Developers

    Learn modern unit testing in C# from scratch! This course by Nick Chapsas teaches you how to write reliable, maintainable unit tests, covering key concepts, techniques, and real-world applications.

    About This Course

    There is a reason why Unit Testing is the bottom layer in the testing pyramid. You can only build a solid testing suite on a robust foundation. Nothing is more reassuring when working on a codebase than knowing that if you accidentally break something, a test will alert you, saving you hundreds to thousands or even hundreds of thousands of dollars in potential customer impact. In this course, Nick will teach you how to write modern unit tests for your code bases so you are always confident in change. Oh, and if you don't know what the testing pyramid is, don't worry. You will after you take this course.

    Course Curriculum

    3h 39m 8 sections
    Welcome
    02:21 Free preview
    What will you learn in this course?
    03:55 Free preview
    Who is this course for and prerequisites
    01:49 Free preview
    Different types of testing
    07:15
    What is unit testing and why it's important?
    01:30
    The testing pyramid
    01:57
    Why should you write unit tests?
    03:12
    The 3 core unit testing concepts
    01:57
    Why xUnit?
    00:57
    Writing your first unit test
    06:23
    Structuring your solution
    02:50
    Naming in unit tests
    03:32
    Arrange, Act, Assert
    02:09
    xUnit's test execution model
    02:54
    Test Setup and Teardown
    05:46
    Parameterizing tests
    03:18
    Ignoring tests
    01:23
    Your turn to practice
    01:04
    My answer to the exercise
    00:40
    Section recap
    00:48
    Writing fluent assertions
    03:19
    Testing strings
    02:58
    Testing numbers
    02:00
    Testing dates
    01:37
    Testing objects
    03:32
    Testing enumerables
    03:32
    Testing methods that throw Exceptions
    02:23
    Testing for raised events
    01:29
    Testing private methods (members)
    01:24
    Testing internal methods (members)
    03:01
    Section recap
    00:26
    The problem with dependencies
    03:54
    Dependency injection to the rescue
    02:55
    What are fakes?
    03:03
    What is mocking?
    06:11
    Moq vs NSubstitute
    02:35
    Section recap
    00:53
    The project we will be adding unit tests to
    03:38
    The scope of our testing
    03:59
    Testing the application layer
    22:35
    Exercise: Testing the rest of the application layer
    01:24
    Exercise answer: Testing the rest of the application layer
    15:21
    But was all that necessary?
    02:10
    Testing the data layer
    01:13
    Testing the API layer
    09:51
    Exercise: Testing the rest of the API layer
    01:03
    Exercise answer: Testing the rest of the API layer
    13:19
    Section recap
    00:42
    Observing the default test execution behavior
    02:41
    The Class Fixture
    04:12
    The Collection Fixture
    05:04
    Running test in parallel
    05:43
    Advanced parameterization
    04:53
    Setting test execution timeouts
    01:17
    Testing Date and Time
    05:19
    Continuous testing
    01:55
    What is code coverage?
    02:57
    Measuring code coverage
    06:35
    Section recap
    00:48
    Course conclusion
    00:37

    Meet Your Instructor

    Nick Chapsas

    Nick Chapsas

    Nick Chapsas is a .NET & C# content creator, educator and a Microsoft MVP for Developer Technologies with years of experience in Software Engineering and Engineering Management.

    He has worked for some of the biggest companies in the world, building systems that served millions of users and tens of thousands of requests per second.

    Nick creates free content on YouTube and is the host of the Keep Coding Podcast.

    View all courses by Nick Chapsas

    What's New

    Getting Started: Model Context Protocol (MCP)
    course

    Getting Started: Model Context Protocol (MCP)

    Learn how to get started with the Model Context Protocol (MCP) and integrate it into your applications.

    Learn more about Getting Started: Model Context Protocol (MCP)
    Hands-On: Learn TypeScript
    course

    Hands-On: Learn TypeScript

    Learn TypeScript through hands-on coding exercises. Practice what you learn with interactive challenges designed for every level.

    Learn more about Hands-On: Learn TypeScript
    Hands-On: Learn JavaScript
    course

    Hands-On: Learn JavaScript

    Learn JavaScript through hands-on coding exercises. Practice what you learn with interactive challenges designed for every level.

    Learn more about Hands-On: Learn JavaScript
    Hands-On: Data Structures & Algorithms in C#
    course

    Hands-On: Data Structures & Algorithms in C#

    Master data structures and algorithms through hands-on coding exercises in C#. Free to enroll for 7 days!

    Learn more about Hands-On: Data Structures & Algorithms in C#
    Blogsmith.ai
    feature

    Blogsmith.ai

    Turn your videos into blogs and newsletters with AI. Check out our new product at blogsmith.ai.

    Learn more about Blogsmith.ai
    Leaderboard
    feature

    Leaderboard

    See how you stack up against other learners. Track your progress, climb the ranks, and compete with the Dometrain community.

    Learn more about Leaderboard
    Hands-On: Learn PostgreSQL
    course

    Hands-On: Learn PostgreSQL

    Learn PostgreSQL through hands-on coding exercises. Practice what you learn with interactive challenges designed for every level.

    Learn more about Hands-On: Learn PostgreSQL
    Free Hands-On: C# for Beginners
    course

    Free Hands-On: C# for Beginners

    Learn C# through hands-on coding exercises. Practice what you learn with interactive challenges designed for everyone, from beginners to experts.

    Learn more about Free Hands-On: C# for Beginners
    Getting Started: AI for .NET Developers
    course

    Getting Started: AI for .NET Developers

    Get started with integrating AI into your .NET applications effectively using the latest LLM best practices.

    Learn more about Getting Started: AI for .NET Developers
    Getting Started: Building .NET Applications on AWS
    course

    Getting Started: Building .NET Applications on AWS

    Learn how to build and deploy .NET applications on AWS using CDK, Lambda, DynamoDB, S3, and more.

    Learn more about Getting Started: Building .NET Applications on AWS
    What's new in C# 14
    blog

    What's new in C# 14

    This guide covers every new C# 14 feature, explains its benefits, and provides practical code examples to help you navigate how you can use them.

    Learn more about What's new in C# 14
    Let's Build It: AI Chatbot with RAG in .NET Using Your Data
    course

    Let's Build It: AI Chatbot with RAG in .NET Using Your Data

    Build a Retrieval-Augmented Generation (RAG) chatbot that can answer questions using your data.

    Learn more about Let's Build It: AI Chatbot with RAG in .NET Using Your Data
    From Zero to Hero: SignalR in .NET
    course

    From Zero to Hero: SignalR in .NET

    Enable enterprise-grade real-time communication for your web apps with SignalR.

    Learn more about From Zero to Hero: SignalR in .NET
    Deep Dive: Solution Architecture
    course

    Deep Dive: Solution Architecture

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

    Learn more about Deep Dive: Solution Architecture
    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 about Migrating: ASP.NET Web APIs to ASP.NET Core
    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 about Getting Started: Caching in .NET
    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 about From Zero to Hero: Testing with xUnit in C#
    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 about Create a ChatGPT Console AI Chatbot in C#