Xunit: Analyzer to detect logging calls in tests

Created on 8 May 2017  路  4Comments  路  Source: xunit/xunit

Based on #745, analyzer that detects calls to System.Console, System.Diagnostics.Debug, System.Diagnostics.Trace, and maybe others (System.Console.Error?). The fix provider would suggest using ITestOutputHelper (as per http://xunit.github.io/docs/capturing-output.html), including injecting it into the test class via constructor.

Things to consider:

  • there are lots of variants of the Write/WriteLine methods, what would be the appropriate refactoring for each?
  • when injecting the output helper, consider making sure that test class hierarchies still compile
Analyzers help wanted Feature

All 4 comments

~@marcind I'm about to implement this. You can assign me if possible.~

~Some opinions/thoughts:~

  • ~Should all invocations (no matter if Trace, Debug, Console) be redirected to ITestOutputHelper ? I think yes.~
  • ~Fix can add a call to ToString() for all non-string literal types; or add additional methods on ITestOutputHelper. I would prefer ToString() calls.~
  • ~Either add additional methods for Write, Write[Line]If; or add if statements when transforming; or don't provide a fix. I would prefer to not provide a fix; conditional test code is bad.~

Update: not of relevance anymore

@marcind ping 馃槃

@marcind ping

given the plan for v3 is to add Console / Trace / Debugger capture support perhaps this one should be closed?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bradwilson picture bradwilson  路  3Comments

jonparky picture jonparky  路  3Comments

FreeApophis picture FreeApophis  路  3Comments

JohnRusk picture JohnRusk  路  3Comments

casos92 picture casos92  路  4Comments