@@ -47,10 +47,10 @@ public class NUnitEventListener :
47
47
ITestEventListener , IDisposable // Public for testing
48
48
{
49
49
private static readonly ICollection < INUnitTestEventTestOutput> EmptyNodes = new List< INUnitTestEventTestOutput> ( ) ;
50
- private readonly ITestExecutionRecorder _recorder ;
51
- private readonly ITestConverterCommon _testConverter ;
52
- private readonly IAdapterSettings _settings ;
53
- private readonly Dictionary < string , ICollection< INUnitTestEventTestOutput>> _outputNodes = new ( ) ;
50
+ private readonly ITestExecutionRecorder recorder ;
51
+ private readonly ITestConverterCommon testConverter ;
52
+ private readonly IAdapterSettings settings ;
53
+ private readonly Dictionary < string , ICollection< INUnitTestEventTestOutput>> outputNodes = new ( ) ;
54
54
55
55
#if NET35
56
56
public override object InitializeLifetimeService( )
@@ -69,9 +69,9 @@ public NUnitEventListener(ITestConverterCommon testConverter, INUnit3TestExecuto
69
69
{
70
70
this . executor = executor ;
71
71
dumpXml = executor . Dump ;
72
- _settings = executor . Settings ;
73
- _recorder = executor . FrameworkHandle ;
74
- _testConverter = testConverter ;
72
+ settings = executor . Settings ;
73
+ recorder = executor . FrameworkHandle ;
74
+ this . testConverter = testConverter ;
75
75
}
76
76
77
77
#region ITestEventListener
@@ -103,8 +103,8 @@ public void OnTestEvent(string report)
103
103
}
104
104
catch ( Exception ex )
105
105
{
106
- _recorder . SendMessage ( TestMessageLevel . Warning , $ "Error processing { node . Name } event for { node . FullName } ") ;
107
- _recorder . SendMessage ( TestMessageLevel . Warning , ex . ToString ( ) ) ;
106
+ recorder . SendMessage ( TestMessageLevel . Warning , $ "Error processing { node . Name } event for { node . FullName } ") ;
107
+ recorder . SendMessage ( TestMessageLevel . Warning , ex . ToString ( ) ) ;
108
108
}
109
109
}
110
110
@@ -141,44 +141,44 @@ protected virtual void Dispose(bool disposing)
141
141
142
142
public void TestStarted ( INUnitTestEventStartTest testNode )
143
143
{
144
- var ourCase = _testConverter . GetCachedTestCase ( testNode . Id ) ;
144
+ var ourCase = testConverter . GetCachedTestCase ( testNode . Id ) ;
145
145
146
146
// Simply ignore any TestCase not found in the cache
147
147
if ( ourCase != null )
148
- _recorder . RecordStart ( ourCase ) ;
148
+ recorder . RecordStart ( ourCase ) ;
149
149
}
150
150
151
151
public void TestFinished ( INUnitTestEventTestCase resultNode )
152
152
{
153
153
var testId = resultNode . Id ;
154
- if ( _outputNodes . TryGetValue ( testId , out var outputNodes ) )
154
+ if ( this . outputNodes . TryGetValue ( testId , out var outputNodes ) )
155
155
{
156
- _outputNodes . Remove ( testId ) ;
156
+ this . outputNodes . Remove ( testId ) ;
157
157
}
158
158
159
- var result = _testConverter . GetVsTestResults ( resultNode , outputNodes ?? EmptyNodes ) ;
160
- if ( _settings . ConsoleOut == 1 )
159
+ var result = testConverter . GetVsTestResults ( resultNode , outputNodes ?? EmptyNodes ) ;
160
+ if ( settings . ConsoleOut == 1 )
161
161
{
162
162
if ( ! string . IsNullOrEmpty ( result . ConsoleOutput ) && result . ConsoleOutput != NL )
163
163
{
164
164
string msg = result . ConsoleOutput ;
165
- if ( _settings . UseTestNameInConsoleOutput )
165
+ if ( settings . UseTestNameInConsoleOutput )
166
166
msg = $ "{ resultNode . Name } : { msg } ";
167
- _recorder . SendMessage ( TestMessageLevel . Informational , msg ) ;
167
+ recorder . SendMessage ( TestMessageLevel . Informational , msg ) ;
168
168
}
169
169
if ( ! string . IsNullOrEmpty ( resultNode . ReasonMessage ) )
170
170
{
171
- _recorder . SendMessage ( TestMessageLevel . Informational , $ "{ resultNode . Name } : { resultNode . ReasonMessage } ") ;
171
+ recorder . SendMessage ( TestMessageLevel . Informational , $ "{ resultNode . Name } : { resultNode . ReasonMessage } ") ;
172
172
}
173
173
}
174
174
175
- _recorder . RecordEnd ( result . TestCaseResult . TestCase , result . TestCaseResult . Outcome ) ;
175
+ recorder . RecordEnd ( result . TestCaseResult . TestCase , result . TestCaseResult . Outcome ) ;
176
176
foreach ( var vsResult in result . TestResults )
177
177
{
178
- _recorder . RecordResult ( vsResult ) ;
178
+ recorder . RecordResult ( vsResult ) ;
179
179
}
180
180
181
- if ( result . TestCaseResult . Outcome == TestOutcome . Failed && _settings . StopOnError )
181
+ if ( result . TestCaseResult . Outcome == TestOutcome . Failed && settings . StopOnError )
182
182
{
183
183
executor . StopRun ( ) ;
184
184
}
@@ -191,15 +191,16 @@ public void SuiteFinished(INUnitTestEventSuiteFinished resultNode)
191
191
var site = resultNode . Site ( ) ;
192
192
if ( site != NUnitTestEvent . SiteType . Setup && site != NUnitTestEvent . SiteType . TearDown )
193
193
return ;
194
- _recorder . SendMessage ( TestMessageLevel . Warning , $ "{ site } failed for test fixture { resultNode . FullName } ") ;
194
+ recorder . SendMessage ( TestMessageLevel . Warning , $ "{ site } failed for test fixture { resultNode . FullName } ") ;
195
195
196
196
if ( resultNode . HasFailure )
197
- _recorder . SendMessage ( TestMessageLevel . Warning , resultNode . FailureMessage ) ;
198
-
199
- // Should not be any stacktrace on Suite-finished
200
- // var stackNode = resultNode.Failure.StackTrace;
201
- // if (!string.IsNullOrEmpty(stackNode))
202
- // _recorder.SendMessage(TestMessageLevel.Warning, stackNode);
197
+ {
198
+ string msg = resultNode . FailureMessage ;
199
+ var stackNode = resultNode . StackTrace ;
200
+ if ( ! string . IsNullOrEmpty ( stackNode ) && settings . IncludeStackTraceForSuites )
201
+ msg += $ "\n StackTrace: { stackNode } ";
202
+ recorder . SendMessage ( TestMessageLevel . Warning , msg ) ;
203
+ }
203
204
}
204
205
205
206
private static readonly string NL = Environment . NewLine ;
@@ -222,16 +223,16 @@ public void TestOutput(INUnitTestEventTestOutput outputNodeEvent)
222
223
string testId = outputNodeEvent . TestId ;
223
224
if ( ! string . IsNullOrEmpty ( testId ) )
224
225
{
225
- if ( ! _outputNodes . TryGetValue ( testId , out var outputNodes ) )
226
+ if ( ! this . outputNodes . TryGetValue ( testId , out var outputNodes ) )
226
227
{
227
228
outputNodes = new List < INUnitTestEventTestOutput > ( ) ;
228
- _outputNodes . Add ( testId , outputNodes ) ;
229
+ this . outputNodes . Add ( testId , outputNodes ) ;
229
230
}
230
231
231
232
outputNodes . Add ( outputNodeEvent ) ;
232
233
}
233
234
234
- _recorder . SendMessage ( TestMessageLevel . Warning , text ) ;
235
+ recorder . SendMessage ( TestMessageLevel . Warning , text ) ;
235
236
}
236
237
}
237
238
}
0 commit comments