SpecFlow.xUnitAdapter icon indicating copy to clipboard operation
SpecFlow.xUnitAdapter copied to clipboard

Exception: No matching step definition found for the step.

Open tedvanderveen opened this issue 8 years ago • 6 comments

When I clone this repository and run the sample test, it works great!

But when I copied the source of the sample project to an existing solution and adjusted bits like assembly and namespaces used to fit in the overall existing solution, I get the test exception result below. But the suggested part of code in the bottom of the details below, is actually available. Any suggestions on how to fix this?

[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9590224]       Stack Trace:
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9590600]            at TechTalk.SpecFlow.UnitTestProvider.XUnitRuntimeProvider.TestPending(String message)
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9590965]            at TechTalk.SpecFlow.ErrorHandling.ErrorProvider.ThrowPendingError(TestStatus testStatus, String message)
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9591260]            at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9591479]            at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9591738]            at SpecFlow.xUnitAdapter.SpecFlowPlugin.Runners.ScenarioTestCaseRunner.ScenarioCleanup()
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9592026]            at SpecFlow.xUnitAdapter.SpecFlowPlugin.Runners.ScenarioTestCaseRunner.RunScenario(SpecFlowDocument gherkinDocument, Scenario scenario)
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9592299]            at SpecFlow.xUnitAdapter.SpecFlowPlugin.Runners.ScenarioTestCaseRunner.<>c__DisplayClass9_0.<RunTestAsync>b__2()
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9592817]       Output:
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9593222]         Given I have entered the following numbers
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9593459]           --- table step argument ---
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9593670]           | number |
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9593886]           | 29     |
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9594068]           | 13     |
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9594228]         -> No matching step definition found for the step. Use the following code to create one:
[1/18/2018 12:18:37 PM Informational] [xUnit.net 00:00:01.9594400]                 [Given(@"I have entered the following numbers")]
public void GivenIHaveEnteredTheFollowingNumbers(Table table)
{
    ScenarioContext.Current.Pending();
}

tedvanderveen avatar Jan 18 '18 12:01 tedvanderveen

Do you get the error when you use it from NuGet? https://www.nuget.org/packages/SpecFlow.xUnitAdapter/

gasparnagy avatar Apr 11 '18 11:04 gasparnagy

@gasparnagy I have the same problem, If I use Bindings from a Nuget packages, it doesn't scan external dlls and then it gives same error.

mtrcn avatar Apr 19 '18 08:04 mtrcn

I have the same problem and it appears to be a long running, persistent issue for many. External assemblies containing step definitions are simply not found. This means that context highlighting in Visual Studio does not work.

HoraceBury avatar Apr 19 '18 12:04 HoraceBury

Not sure if the repo is still in active development or maybe being merged into the main SpecFlow repos?

tedvanderveen avatar Apr 19 '18 16:04 tedvanderveen

I found the solution, I had the same problem with .Net Core project, so I will explain it for .Net Core but you can modify it based on your need, of course.

1: You need to upgrade SpecFlow assemblies to newest version, I forked SpecFlow repository and made few changes to make it build for .Net Standard 2.0. Here is my branch; https://github.com/mtrcn/SpecFlow/tree/netstandard

2: Second, you need to create JSON config file in your SpecFlow project root, like following; specflow.json

{
	"specFlow": {
		"stepAssemblies": [ { "assembly": "Mete.BDD.Bindings" } ]
	}
}

3: Modify following lines;

https://github.com/gasparnagy/SpecFlow.xUnitAdapter/blob/f86e2fe82f7f4bfb5981d700301aea4463e06107/src/SpecFlow.xUnitAdapter.SpecFlowPlugin/Runners/ScenarioTestCaseRunner.cs#L32-L33

with these;

            var containerBuilder = new ContainerBuilder();
            var objectContainer = containerBuilder.CreateGlobalContainer();
            var configurationLoader = objectContainer.Resolve<IConfigurationLoader>();

            var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.GetFullPath(TestCase.FeatureFile.SpecFlowProject.AssemblyPath));

            var testRunnerManager = new TestRunnerManager(
                objectContainer,
                containerBuilder,
                configurationLoader.Load(ConfigurationLoader.GetDefault()),
                objectContainer.Resolve<IRuntimeBindingRegistryBuilder>()
                );
            testRunnerManager.Initialize(assembly);

            testRunner = testRunnerManager.GetTestRunner(Thread.CurrentThread.ManagedThreadId);

This will help you load external bindings that are specified in json config.

Hope it helps!

mtrcn avatar Apr 20 '18 12:04 mtrcn

Any chance you can submit a PR (assuming you can make this work for good old VS2015)?

HoraceBury avatar Apr 20 '18 14:04 HoraceBury