course
Unit Testing with C#
Be more productive by practicing Test-Driven Development (TDD), leveraging advanced tools and frameworks, and applying specialized code patterns.
Description
This practical course will teach you everything you need to know to write effective and maintainable unit tests using Python.
You'll learn how to use Test Driven Development (TDD) to catch bugs early, as well as when to use black-box vs. white-box testing. We'll also dive into the 'world of mocking' with the Moq mocking library, showing you why and how to use it effectively. You'll learn about coverage metrics like code coverage and mutation testing, and we'll explore best practices to help you write efficient and high-quality tests. We will end by implementing integration testing with Testcontainers, so you can be confident that your code works seamlessly with other parts of your system.
At the end of this course, you'll be well-equipped to write unit tests that catch bugs early, reduce maintenance costs, and help you become a better Python developer.
Prior Knowledge
Experience with programming in C# (or see prior knowledge courses on this page)
Subjects
- About testing
- Unit testing basics
- Test Driven Development (TDD)
- Concept of mocking
- Code coverage
- Mocking with MoQ
- Testing frameworks
- Best practices
- Mutation testing
- Integration testing
About testing
In this chapter, you will learn the basics of testing. Why we test and what kind of tests there are.
Goals:
- Know the difference between linting and testing.
- Learn how to categorize all the different kinds of tests.
- Know the testing pyramid and how it can help you to reason about test levels.
- Learn the common anti-patterns and how to recognize them
Unit testing basics
In this chapter, we'll learn the basics of unit testing using the practical example.
Goals:
- Learn how to define the 'unit' to test.
- Learn the difference between white-box and black-box testing.
- Learn to recognize and use naming strategies for our tests.
- Know how to determine when you are 'done' with unit testing.
- Learn basic best practices
- Lab: implement unit tests for a simple library.
Test Driven Development (TDD)
In this chapter, you will learn what TDD is by example.
Goals:
- Learn TDD using the red-green-refactor cycle.
- Lab: Implement a simple library function in a TDD way
Concept of mocking
In this chapter, you will learn what 'mocking' entails and identify where you should use it by identifying your 'system under test' (SUT) and splitting from your 'dependencies'
Goals:
- Learn to identify the SUT from its dependencies
- Learn how to write a mock by hand
- Understand the need for dependency injection when working with mocks.
- Lab: implement dependency injection and setup mocking using classes.
Code Coverage
In this chapter, we will focus on testing metrics, namely code coverage. Goals:
- Know what the difference is between code coverage and mutation testing.
- Know what kinds of coverage metrics there are and how to choose between them.
- Learn the benefits of a quick feedback cycle with code coverage.
- Learn how to run code coverage on our code using the command line.
- Know how to 'break the build' when coverage is too low.
- Lab: use code coverage to improve our tests.
Mocking with MoQ
In this chapter, you will learn to use a mocking library. We will focus on MoQ as an example.
Goals:
- Learn how to install MoQ in your project
- Learn the API; how to create mocks, configure them using
.Setup()
and verify behavior using.Verify()
- Know to use argument matchers using
It.
- Lab: Implement your tests using MoQ
Testing frameworks
In this chapter, we will focus on the 2 most popular testing frameworks in .NET: MSTest and XUnit.
Goals:
- Know why we have two popular frameworks.
- Learn how their APIs compare to each other.
- Learn to parameterize our tests.
- Know what common pitfalls are and how to avoid them.
- Lab: Improve our test maintainability using features of the testing framework.
Best practices
In this chapter, we will look at some best practices we can use to improve the maintainability of our tests further.
Goals:
- Know how to identify tests that are too DRY (Don't Repeat Yourself) or too WET (We Like Typing).
- Learn to prefer DAMP tests (Descriptive and Meaningful Phrases).
- Know when to use a builder pattern
- Know where to find more best practices
- Lab: Implement DAMP tests using the builder pattern.
Mutation testing
In this chapter, we will focus on testing metrics, namely mutation testing.
Goals:
- Know what the difference is between code coverage and mutation testing
- Understand how mutation testing works conceptually.
- Learn what the "mutation score" metric is
- Learn how to use Stryker.NET to run mutation testing on C# code.
- Know how to read a mutation testing report.
- Know how to 'break the build' when the mutation score is too low.
- Lab: Improve the effectiveness of your tests using Stryker.NET.
Integration testing
In this chapter, we'll be 'scaling up the pyramid': Welcome to integration testing.
Goals:
- Be able to identify where an integration test is needed.
- Learn to identify 'shared state' in dependencies.
- Learn how to use Testcontainers to create dependencies on the fly.
- Know what the benefits are of using Testcontainers
- Learn to organize integration tests inside your project structure.
- Lab: Implement integration tests for a database using Testcontainers
Schedule
Start date | Duration | Location | |
---|---|---|---|
December 2, 2024December 3, 2024 | 2 days | Veenendaal / Remote This is a hybrid training and can be followed remotely. More information Veenendaal / Remote This is a hybrid training and can be followed remotely. More information | Sign up |
January 27, 2025January 28, 2025 | 2 days | Utrecht / Remote This is a hybrid training and can be followed remotely. More information Utrecht / Remote This is a hybrid training and can be followed remotely. More information | Sign up |
March 24, 2025March 25, 2025 | 2 days | Veenendaal / Remote This is a hybrid training and can be followed remotely. More information Veenendaal / Remote This is a hybrid training and can be followed remotely. More information | Sign up |
April 10, 2025April 11, 2025 | 2 days | Veenendaal / Remote This is a hybrid training and can be followed remotely. More information Veenendaal / Remote This is a hybrid training and can be followed remotely. More information | Sign up |
April 30, 2025May 1, 2025 | 2 days | Utrecht / Remote This is a hybrid training and can be followed remotely. More information Utrecht / Remote This is a hybrid training and can be followed remotely. More information | Sign up |
All courses can also be conducted within your organization as customized or incompany training.
Our training advisors are happy to help you provide personal advice or find Incompany training within your organization.
Trainers
Prior knowledge courses
C# Hands-on
During this case, participants will use C# to solve various problems, starting with some simple string manipulation and finally performing complex tree manipulation.
- C#/.NET
Programming with C#
Learn how to develop C# applications for the .NET platform
- Architecture
- C#/.NET
- General
Object Oriented Programming in C# By Example
Learn the basics of object Oriented (OO) programming using C #, in a practical manner
- C#/.NET
"Trainer who knows his profession!"Marc
-
Hoge waardering
-
Praktijkgerichte trainingen
-
Gecertificeerde trainers
-
Eigen docenten