Unit Testing 201: Mastering C# Unit Testing with Real-world Examples
Write readable and maintainable unit tests in C# by refactoring real code examples.
π About this course
You've learned the basics of unit testing in C#, but you still struggle with writing tests that are easy to read and maintain.
You've seen too many online tutorials testing a Calculator
class, but you want to learn how to test real code. Code with dependencies, validations, and edge cases. Code that looks like the code you find every day at work.
That's why I created this course.
No more unit testing the Add()
method of a Calculator
class.
In this course, let's refactor some real unit tests to make them more readable and maintainable.
Although I changed names, classes, and methods to avoid disclosing code from past clients and employers, these are the tests I had to work with as a software engineer.
You will learn how to transform messy and convoluted tests into readable and maintainable tests using proven principles and methods.
π¨βπ« Who is this course for?
This course is for you if you are:
- A C# developer who wants to level up your unit testing skills and write better tests
- A C# developer who is tired of boring and unrealistic tutorials and wants to learn from real code examples
After you follow this course, you will be able to:
- Use builder methods to simplify your tests
- Write tests for multiple test values to make your tests more maintainable
- Choose good names and use simple test values to make your tests easier to follow
- Write domain-specific assertion methods to have more readable tests
This is not an introductory course on unit testing.
You should have some basic knowledge of writing unit tests with a testing framework like MSTest, a mocking library like Moq, and the Arrange/Act/Assert pattern.
If you're new to unit testing, check out my ebook Unit Testing 101 first. It will teach you the fundamentals of unit testing in C# β From zero to your first unit tests in C#.
π¦ What is inside?
In this course, you will get access to:
- Eight lessons that cover different best practices for unit testing
- More than ten unit tests that show real code examples that need refactoring
- Four exercises that challenge you to apply what you learned and refactor a unit test on your own
- A checklist that summarizes the best practices from the course
These are the modules and lessons inside:
- Testing AccountController............................4m45s
- Use Builder Methods
- Test IOptions Interface
- Make Test Values Obvious
- (Optional) Check for Missing Configuration Values Inside Constructors
- Testing PaymentRequestValidator...............3m40s
- Use Parameterized Tests
- Use FluentValidation Helpers
- Use Parameterized Tests Insted of Loops
- Testing PaymentService.................................4m35s
- Test a Single Concerned Per Test
- Test Exception Messages
- Testing PayoutService....................................7m17s
- Visually Structure Tests
- (Optional) Use Fakes in Unit Testing
- (Optional) Create Fakes With Moq
- Use TypeBuilder
- Avoid Overspecification
- Testing DictionaryExtensions.......................7m28s
- Use Simple Test Values
- Exercise: Refactor a Test That Merges Dictionaries
- Testing SendEmailCommandHandler.........10m26s
- Test Public Behavior
- Create a Custom Verify Method
- Exercise: Refactor a Test That Stores an Email With Duplicated Addresses
- Testing UpdateStatusCommandHandler..12m11s
- Avoid Hidden Assumptions
- Exercise: Refactor a Test That Updates an Email Status
- Testing ImportGuestsService.......................4m46s
- Use Object Mothers
- Exercise: Refactor a Test That Uploads Guests
π Join "Unit Testing 201"!
If you want to write readable and maintainable unit tests in C# by refactoring real code examples, this course is for you.
Don't miss this chance to master unit testing in C# with real code examples.
Click the "I Want This!" button and join "Unit Testing 201" today to start writing readable and maintainable unit tests in C#.