How to Write Unit Tests for Logging
principal-it.eu
How to Write Unit Tests for Logging
1–10 of 38 posts
Re: How to Write Unit Tests for Logging
#2When doing TDD there is no reason to skip over logging (although that does seem to happen, everyone likes print debugging ;-) it’s just that sometimes it’s a bit clunky to which is why I wrote this tool. It supplies a secondary package that has FluentAssertions extensions to make testing even easier.
Code/packages can be found here: https://github.com/sandermvanvliet/SerilogSinksInMemory
Edit: formatting
Re: How to Write Unit Tests for Logging
#3Re: How to Write Unit Tests for Logging
#4Let's write unit tests for unit tests!
Re: How to Write Unit Tests for Logging
#5a) Logs which break the program semantics when missing. That means, the program does not work "as expected" anymore for any directly or indirectly impacted enduser.
b) Logs that have no semantic impact when missing. No one will notice that they are missing, unless there is any other problem. These logs are solely meant to better understand the program operations.
Logs of type A should be tested like everything else. But logs of type B - I don't think I would test them.
While it is not nice to have a failure in production and figuring out only at that time that the logging doesn't work, I think that is even worse to break tests because of logging changes. Logging usually is so easy that it is an all- or nothing thing. I'm not saying that it does not have advantages to test for these kind of logs, but from my experience it is not worth the costs in 99% of the cases.
Re: How to Write Unit Tests for Logging
#6Let's write unit tests for unit tests!
Re: How to Write Unit Tests for Logging
#7Let's write unit tests for unit tests!
The build asserted that the number of failing unit tests was 0.
It turns out that "breaking the unit test library completely such that 0 tests run instead of all thousands of them" did not break the build.
When someone noticed a week later, that was not fun to clean up.
Re: How to Write Unit Tests for Logging
#8Re: How to Write Unit Tests for Logging
#9Let's write unit tests for unit tests!
- most test frameworks use unittests to test themselves.
- tests need to have value. the dev/team/organization needs to come up with the sensible measure of value that guides poeople what to test and how to test it.