Closed 304NotModified closed 4 years ago
Let me investigate and I will get back to you.
FYI:
<TargetFramework>netcoreapp2.1</TargetFramework>
tried also static
class, but that won't help either.
The big difference is here (I think), that we're using MSTest and not xUnit
I found the issue (I have checked out the repo)
If the dependency isn't found, you will get this nasty exception.
So:
namespace SolidToken.SpecFlow.DependencyInjection.Tests
{
public static class TestDependencies
{
[ScenarioDependencies]
public static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
//// Add test dependencies
//services.AddTransient<ITestService, TestService>();
//// ContextInjectionScope (by using AddScoped instead of AddTransient, the context will be scoped to the Feature across bindings)
//services.AddScoped<TestContext>();
//// NOTE: This line is essential so that Microsoft.Extensions.DependencyInjection knows
//// about the SpecFlow bindings (something normally BoDi does automatically).
//// TODO: Find out if we can make this part of the Plugin
//foreach (var type in typeof(TestDependencies).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))))
//{
// services.AddSingleton(type);
//}
return services;
}
}
}
Will demo the issue
Is it possible that you have not registered any bindings (yet)?
For example, if you look at DependencyInjectionPluginSteps.cs you will notice the [Binding]
tag that will bind the code to the SpecFlow Feature file.
Currently the plugin requires you to register all the bindings/step definitions (otherwise the DI framework can't find them). So your initialisation code should look like:
var services = new ServiceCollection();
foreach (var type in typeof(TestDependencies).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))))
{
services.AddSingleton(type);
}
return services;
Although this is in the README.md
, I don't think it is very intuitive and I want to solve it as part of issue #7 but haven't landed on a solution yet.
ow yes indeed. I missed that! That's the fix.
Would be great if we could make that optional.
@mbhoek check https://github.com/solidtoken/SpecFlow.DependencyInjection/pull/25 :)
This could be closed.
Hi,
I added this to my specflow project:
and
And now I get for all tests:
any idea?
Update: same issue with 0.3.1 and 0.2.4. What am I missing?