An open API service indexing awesome lists of open source software.

https://github.com/dotnet-labs/unittestingwithilogger

Unit Testing with .NET Core ILogger<T>
https://github.com/dotnet-labs/unittestingwithilogger

dotnet dotnet5 dotnet6 dotnetcore dotnetcore3 logging mock moq testing unit-testing unittest

Last synced: 6 months ago
JSON representation

Unit Testing with .NET Core ILogger<T>

Awesome Lists containing this project

README

          

# Unit Testing with .NET Core `ILogger`

Buy Me a Coffee at ko-fi.com

## [Medium Article](https://codeburst.io/unit-testing-with-net-core-ilogger-t-e8c16c503a80)

Because `ILogger` objects are frequently used in controllers and service classes, we cannot avoid them in unit tests. In this post, we will go over some common ways to work with `ILogger` objects in unit testing.

1. Replace `ILogger` with `NullLogger`
2. Create a Real `ILogger` that Logs to Console
3. Mock an `ILogger` Object

## License

Feel free to use the code in this repository as it is under MIT license.

Buy Me a Coffee at ko-fi.com