Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Mastering C# Unit Testing with Real-world Examples
Rating: 4.2 out of 5(9 ratings)
54 students

Mastering C# Unit Testing with Real-world Examples

Learn C# unit testing best practices by refactoring real-world examples.
Created byCesar Aguirre
Last updated 4/2024
English

What you'll learn

  • Use builder methods to simplify your tests
  • Write tests for multiple test values to make your tests more maintainable
  • Choose good names to express the intent of your tests
  • Use simple test values to make your tests easier to follow
  • Write domain-specific assertion methods to have more readable tests

Course content

6 sections24 lectures1h 3m total length
  • Getting Started2:48

    Welcome! No more tests for a Calculator class. Let's learn unit testing best practices by refactoring real tests. Directly in Visual Studio. No boring slides, I promise.

Requirements

  • Basic knowledge of writing unit tests with a testing framework like MSTest
  • Understading of mocks and mocking libraries like Moq
  • Familiarity with the Arrange/Act/Assert pattern

Description

Have you learned the basics of unit testing in C#, but you still struggle with writing tests that are easy to read and maintain?

Have you 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 using proven principles and methods.

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.


Who Is This For?

This course is for C# developers who:

  • Know what MSTest, Moq, and AAA mean.

  • Want to write readable and maintainable unit tests.

  • Are tired of boring, unrealistic tutorials and want to learn from real code examples.


What You’ll Learn

By the end of this course, you’ll be able to:

  • Simplify tests with builder methods.

  • Write maintainable tests easily with parameterized values.

  • Make tests clear and easy to follow with good names and test values.

  • Have more readable tests with domain-specific assertion methods.

Mastering these skills will help you to write tests easy to follow, easy to maintain, and easy to trust.

The next time you open one of your tests, you’ll know exactly what’s going on.


Important Note:

This is not an introductory course. We won't cover how to write your first unit tests.

If you already know what mocks are and when to use them, you're ready for this.


What's Inside

In this course, you will get access to:

  • 8 lessons covering different best practices for unit testing.

  • 10+ real unit tests that need refactoring.

  • 4 hands-on exercises to apply what you've learned.

  • 1 checklist summarizing all best practices.


Ready to master unit testing with real-world examples? Fire up your Visual Studio and let's start writing clean, readable, and maintainable unit tests—the kind of tests your future self and your teammates will thank you for.

See you in Lesson 1!

Who this course is for:

  • C# developers looking to improve their unit testing skills and write readable and maintainable tests
  • C# developers tired of boring and impractical tutorials that prefer to learn through real-world code examples