nunit.analyzers icon indicating copy to clipboard operation
nunit.analyzers copied to clipboard

Analyzer: warn on Console.WriteLine in tests.

Open JohanLarsson opened this issue 6 years ago • 3 comments

Happens that things are dumped when debugging tests and then forgotten. Reasons to remove:

  1. They slow down tests.
  2. Pollute CI logs.

JohanLarsson avatar Sep 15 '18 10:09 JohanLarsson

Sounds reasonable.

mikkelbu avatar Sep 19 '18 21:09 mikkelbu

@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 avatar Apr 01 '24 02:04 Bartleby2718

@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.

manfred-brands avatar Apr 01 '24 03:04 manfred-brands