nunit.analyzers
nunit.analyzers copied to clipboard
Analyzer: warn on Console.WriteLine in tests.
Happens that things are dumped when debugging tests and then forgotten. Reasons to remove:
- They slow down tests.
- Pollute CI logs.
Sounds reasonable.
@JohanLarsson @mikkelbu Out of curiosity, what is the suggested alternative if you need to log timestamps for testing purposes? For example, you could imagine using Console.WriteLine
when coming up with a repro like https://github.com/Bartleby2718/nunit-parallel-execution/commit/e059d1b4badbf7110817c02bba8f55924f0a4357.
@Bartleby2718 Purely outputting text, regardless how in a CI build means nobody looks at them if the build is green. Even if the build is red, if a lot of tests output "stuff" it is hard to find the actual error amongst it. If you want to assert any regression, measure it and then do an actual assert on the elapsed time, e.g. elapsed time < 1s. But with differences in runners or contention in case of parallel test you still might get false positives.
If you want to keep output in for later verification if the above test fails, you can do this conditionally.
Either compile time, e.g. "#if VERBOSE" or runtime by setting an Environment Variable or a flag.
Although NUnit has a conditional logger it is in an Internal
namespace and an end-user cannot set the level.