Skip to content

Commit

Permalink
Should not log error if TestAssembly does not have a RuntimePlugin at…
Browse files Browse the repository at this point in the history
…tribute (#2462)

* Should not log error if TestAssembly does not have a RuntimePlugin attribute

* Update changelog

* Remove Debugger
  • Loading branch information
epresi authored Jul 13, 2021
1 parent af4319f commit 31d3cc2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
15 changes: 11 additions & 4 deletions TechTalk.SpecFlow/Infrastructure/ContainerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,23 @@ protected virtual void LoadPlugins(IRuntimeConfigurationProvider configurationPr
var traceListener = container.Resolve<ITraceListener>();
foreach (var pluginPath in pluginLocator.GetAllRuntimePlugins())
{
LoadPlugin(pluginPath, pluginLoader, runtimePluginEvents, unitTestProviderConfigration, traceListener);
// Should not log error if TestAssembly does not have a RuntimePlugin attribute
var traceMissingPluginAttribute = !testAssembly.Location.Equals(pluginPath);
LoadPlugin(pluginPath, pluginLoader, runtimePluginEvents, unitTestProviderConfigration, traceListener, traceMissingPluginAttribute);
}
}

protected virtual void LoadPlugin(string pluginPath, IRuntimePluginLoader pluginLoader, RuntimePluginEvents runtimePluginEvents,
UnitTestProviderConfiguration unitTestProviderConfigration, ITraceListener traceListener)
protected virtual void LoadPlugin(
string pluginPath,
IRuntimePluginLoader pluginLoader,
RuntimePluginEvents runtimePluginEvents,
UnitTestProviderConfiguration unitTestProviderConfigration,
ITraceListener traceListener,
bool traceMissingPluginAttribute)
{
traceListener.WriteToolOutput($"Loading plugin {pluginPath}");

var plugin = pluginLoader.LoadPlugin(pluginPath, traceListener);
var plugin = pluginLoader.LoadPlugin(pluginPath, traceListener, traceMissingPluginAttribute);
var runtimePluginParameters = new RuntimePluginParameters();

plugin?.Initialize(runtimePluginEvents, runtimePluginParameters, unitTestProviderConfigration);
Expand Down
2 changes: 1 addition & 1 deletion TechTalk.SpecFlow/Plugins/IRuntimePluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace TechTalk.SpecFlow.Plugins
{
public interface IRuntimePluginLoader
{
IRuntimePlugin LoadPlugin(string pluginAssemblyName, ITraceListener traceListener);
IRuntimePlugin LoadPlugin(string pluginAssemblyName, ITraceListener traceListener, bool traceMissingPluginAttribute);
}
}
6 changes: 4 additions & 2 deletions TechTalk.SpecFlow/Plugins/RuntimePluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace TechTalk.SpecFlow.Plugins
{
public class RuntimePluginLoader : IRuntimePluginLoader
{
public IRuntimePlugin LoadPlugin(string pluginAssemblyName, ITraceListener traceListener)
public IRuntimePlugin LoadPlugin(string pluginAssemblyName, ITraceListener traceListener, bool traceMissingPluginAttribute)
{
Assembly assembly;
try
Expand All @@ -25,7 +25,9 @@ public IRuntimePlugin LoadPlugin(string pluginAssemblyName, ITraceListener trace
var pluginAttribute = (RuntimePluginAttribute)Attribute.GetCustomAttribute(assembly, typeof(RuntimePluginAttribute));
if (pluginAttribute == null)
{
traceListener.WriteToolOutput(string.Format("Missing [assembly:RuntimePlugin] attribute in {0}. Please check https://go.specflow.org/doc-plugins for details.", assembly.FullName));
if (traceMissingPluginAttribute)
traceListener.WriteToolOutput(string.Format("Missing [assembly:RuntimePlugin] attribute in {0}. Please check https://go.specflow.org/doc-plugins for details.", assembly.FullName));

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Can_load_Windsor_plugin()
var loader = new RuntimePluginLoader();
var listener = new Mock<ITraceListener>();

var plugin = loader.LoadPlugin("SpecFlow.Windsor.SpecFlowPlugin.dll", listener.Object);
var plugin = loader.LoadPlugin("SpecFlow.Windsor.SpecFlowPlugin.dll", listener.Object, It.IsAny<bool>());

plugin.Should().NotBeNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public override void RegisterGlobalContainerDefaults(BoDi.ObjectContainer contai

var pluginLoaderStub = new Mock<IRuntimePluginLoader>();
var traceListener = container.Resolve<ITraceListener>();
pluginLoaderStub.Setup(pl => pl.LoadPlugin(It.IsAny<string>(), traceListener)).Returns(_pluginToReturn);
pluginLoaderStub.Setup(pl => pl.LoadPlugin(It.IsAny<string>(), traceListener, It.IsAny<bool>())).Returns(_pluginToReturn);


container.RegisterInstanceAs<IRuntimePluginLocator>(runtimePluginLocator.Object);
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changes:
Fixes:
+ Fix Type or namespace [TestNamespace]_XunitAssemblyFixture could not be found #1825
+ Fix Default value deserialization from specflow.json #2239 #2439
+ Should not log error if TestAssembly does not have a RuntimePlugin attribute #2432


3.8
Expand Down

0 comments on commit 31d3cc2

Please sign in to comment.