Skip to content

Commit

Permalink
Unit test provider independent ISpecFlowOutputHelper implementation (#…
Browse files Browse the repository at this point in the history
…2111)

* ISpecFlowOutputHelper to write to scenario output independently of used runner plugin

* Adapt tests to handle runner specific std out
  • Loading branch information
tzongithub authored Sep 7, 2020
1 parent 7d9f55b commit cf72078
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 47 deletions.
30 changes: 0 additions & 30 deletions Plugins/TechTalk.SpecFlow.xUnit.SpecFlowPlugin/OutputHelper.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginPar
{
runtimePluginEvents.RegisterGlobalDependencies += RuntimePluginEvents_RegisterGlobalDependencies;
runtimePluginEvents.CustomizeTestThreadDependencies += RuntimePluginEvents_CustomizeTestThreadDependencies;
runtimePluginEvents.CustomizeScenarioDependencies += RuntimePluginEvents_CustomizeScenarioDependencies;
unitTestProviderConfiguration.UseUnitTestProvider("xunit");
}

Expand All @@ -31,12 +30,5 @@ private void RuntimePluginEvents_CustomizeTestThreadDependencies(object sender,

container.RegisterTypeAs<XUnitTraceListener, ITraceListener>();
}

private void RuntimePluginEvents_CustomizeScenarioDependencies(object sender, CustomizeScenarioDependenciesEventArgs e)
{
var container = e.ObjectContainer;

container.RegisterTypeAs<OutputHelper, ISpecFlowOutputHelper>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public virtual void RegisterTestThreadContainerDefaults(ObjectContainer testThre
public void RegisterScenarioContainerDefaults(ObjectContainer scenarioContainer)
{
scenarioContainer.RegisterTypeAs<SpecFlowOutputHelper, ISpecFlowOutputHelper>();

scenarioContainer.RegisterTypeAs<SpecFlowScenarioOutputTracer, ISpecFlowScenarioOutputListener>("tracer");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TechTalk.SpecFlow.Infrastructure
{
public interface ISpecFlowScenarioOutputListener
{
void OnMessage(string message);
}
}
21 changes: 16 additions & 5 deletions TechTalk.SpecFlow/Infrastructure/SpecFlowOutputHelper.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BoDi;

namespace TechTalk.SpecFlow.Infrastructure
{
public class SpecFlowOutputHelper : ISpecFlowOutputHelper
{
private readonly IObjectContainer _container;

public SpecFlowOutputHelper(IObjectContainer container)
{
_container = container;
}

private IEnumerable<ISpecFlowScenarioOutputListener> Listeners =>
_container.ResolveAll<ISpecFlowScenarioOutputListener>();

public void WriteLine(string message)
{
Console.WriteLine(message);
foreach (var listener in Listeners)
{
listener.OnMessage(message);
}
}

public void WriteLine(string format, params object[] args)
{
Console.WriteLine(format, args);
WriteLine(string.Format(format, args));
}
}
}
19 changes: 19 additions & 0 deletions TechTalk.SpecFlow/Infrastructure/SpecFlowScenarioOutputTracer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using TechTalk.SpecFlow.Tracing;

namespace TechTalk.SpecFlow.Infrastructure
{
public class SpecFlowScenarioOutputTracer : ISpecFlowScenarioOutputListener
{
private readonly ITraceListener _traceListener;

public SpecFlowScenarioOutputTracer(ITraceListener traceListener)
{
_traceListener = traceListener;
}

public void OnMessage(string message)
{
_traceListener.WriteTestOutput(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void ThenEveryScenarioHasItSIndividualContextId()

foreach (var testResult in lastTestExecutionResult.TestResults)
{
var contextIdLines = testResult.StdOut.SplitByString(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries).Where(s => s.Contains("Context ID"));
var contextIdLines = testResult.StdOut.Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries).Where(s => s.StartsWith("Context ID"));

var distinctContextIdLines = contextIdLines.Distinct();

Expand Down
5 changes: 3 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
3.4.4
Changes:
+ Unit test provider independent ISpecFlowOutputHelper implementation

Fixes:
+ Support dynamic assemblies in container initialization #2110

3.4
3.4.3

Changes:
+ Allow incremental builds to work correctly for projects with MSTest/NUnit/xUnit integration
Expand Down

0 comments on commit cf72078

Please sign in to comment.