C# Unit Testing Best Practices for Great Code Coverage

Channel Avatar
Comment
X
Share
C# Unit Testing Best Practices for Great Code Coverage
C# Unit Testing Best Practices for Great Code Coverage
Accelerate your Clean Architecture skills: https://bit.ly/3PupkOJ

Support me on Patreon to access the source code: https://www.patreon.com/milanjovanovic

In this video, I will show you how to unit-test domain services. Unit testing domain services is easy since most dependencies will be injected as interfaces. We will use NSubstitute to provide mocks while unit testing and use FluentAssertion to verify that our services behaved as expected. I’ll also discuss code coverage and why you don’t want to focus on that specific metric. Instead, focus on writing high-quality unit tests.

Join my weekly .NET newsletter:
https://www.milanjovanovic.tech

Read my Blog here:
https://www.milanjovanovic.tech/blog

Chapters
0:00 What are we going to test?
1:08 Implementing the first test case
4:10 Improving the test class setup
5:50 Implementing the second test case
7:11 Mocking external dependencies with NSubstitute
11:09 Writing the test case for the happy path
12:47 How to verify method calls on your mock with NSubstitute
15:50 Code coverage report – just focus on writing good unit tests

Take the opportunity to connect and share this video with your friends and family if you find it useful.

Keywords: unit test, unit testing, unit testing c#, unit testing vs integration testing, unit testing command handlers, unit testing handlers, unit testing cqrs handlers, unit testing cqrs, unit testing .net, unit testing .net 6, xunit, fluentassertions, mock, testing, tests, test, verify, code coverage, coverage, 100% coverage, command handler unit test, moq unit test, fluentassertions unit test, nsubstitute, nsubstitute tutorial, nsubstitute mock, nsubstitute verify, nsubstitute test

Read Also

Leave a Reply

Your email address will not be published. Required fields are marked *