-
Notifications
You must be signed in to change notification settings - Fork 11
System.NullReferenceException inside TechTalk.SpecFlow #24
Comments
Let me investigate and I will get back to you. |
FYI:
tried also 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 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 |
ow yes indeed. I missed that! That's the fix. Would be great if we could make that optional. |
Initial thought was that issue #24 was cause by using the MSTest testing framework. Although this was not the case, it does make sense to add tests based on MSTest testing framework. Still needs cleanup (rename the existing XUnit test project), support for both 2.1 and 3.1 SDK and investigate whether it is possible to code share between MSTest and XUnit test project.
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?
The text was updated successfully, but these errors were encountered: