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>
- Host: GitHub
- URL: https://github.com/dotnet-labs/unittestingwithilogger
- Owner: dotnet-labs
- License: mit
- Created: 2020-07-08T13:07:10.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-12-08T18:05:56.000Z (almost 2 years ago)
- Last Synced: 2025-03-24T22:40:49.145Z (6 months ago)
- Topics: dotnet, dotnet5, dotnet6, dotnetcore, dotnetcore3, logging, mock, moq, testing, unit-testing, unittest
- Language: C#
- Homepage:
- Size: 12.7 KB
- Stars: 11
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Unit Testing with .NET Core `ILogger`
## [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.