Skip to content

Commit 0a3b03c

Browse files
Adding TearDown to dump the context (base test class)
1 parent 7f24cb9 commit 0a3b03c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/ServiceControl.AcceptanceTesting/NServiceBusAcceptanceTest.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
namespace ServiceControl.AcceptanceTesting
22
{
3+
using System;
34
using System.Linq;
45
using System.Threading;
6+
using NServiceBus.AcceptanceTesting;
57
using NServiceBus.AcceptanceTesting.Customization;
68
using NServiceBus.Logging;
79
using NUnit.Framework;
10+
using NUnit.Framework.Interfaces;
11+
using NUnit.Framework.Internal;
812

913
/// <summary>
1014
/// Base class for all the NSB test that sets up our conventions
@@ -35,5 +39,34 @@ public void SetUp()
3539
return testName + "." + endpointBuilder;
3640
};
3741
}
42+
43+
[TearDown]
44+
public void TearDown()
45+
{
46+
if (!TestExecutionContext.CurrentContext.TryGetRunDescriptor(out var runDescriptor))
47+
{
48+
return;
49+
}
50+
51+
var scenarioContext = runDescriptor.ScenarioContext;
52+
53+
TestContext.Out.WriteLine($@"Test settings:
54+
{string.Join(Environment.NewLine, runDescriptor.Settings.Select(setting => $" {setting.Key}: {setting.Value}"))}");
55+
56+
TestContext.Out.WriteLine($@"Context:
57+
{string.Join(Environment.NewLine, scenarioContext.GetType().GetProperties().Select(p => $"{p.Name} = {p.GetValue(scenarioContext, null)}"))}");
58+
59+
if (TestExecutionContext.CurrentContext.CurrentResult.ResultState == ResultState.Failure || TestExecutionContext.CurrentContext.CurrentResult.ResultState == ResultState.Error)
60+
{
61+
TestContext.Out.WriteLine(string.Empty);
62+
TestContext.Out.WriteLine($"Log entries (log level: {scenarioContext.LogLevel}):");
63+
TestContext.Out.WriteLine("--- Start log entries ---------------------------------------------------");
64+
foreach (var logEntry in scenarioContext.Logs)
65+
{
66+
TestContext.Out.WriteLine($"{logEntry.Timestamp:T} {logEntry.Level} {logEntry.Endpoint ?? TestContext.CurrentContext.Test.Name}: {logEntry.Message}");
67+
}
68+
TestContext.Out.WriteLine("--- End log entries ---------------------------------------------------");
69+
}
70+
}
3871
}
3972
}

0 commit comments

Comments
 (0)