SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.22k stars 751 forks source link

Multiple public constructors with same maximum parameter count are not supported! #2718

Open ccarmannt opened 11 months ago

ccarmannt commented 11 months ago

SpecFlow Version

3.9.74

Which test runner are you using?

NUnit

Test Runner Version Number

3.13.3

.NET Implementation

equal or greater .NET Framework 4.6.1

Project Format of the SpecFlow project

Classic project format using packages.config

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

SpecFlow Section in app.config or content of specflow.json

n/a

Issue Description

Received this error when attempting a test run:

OneTimeSetUp: BoDi.ObjectContainerException : Multiple public constructors with same maximum parameter count are not supported! System.Globalization.CultureInfo (resolution path: TechTalk.SpecFlow.FeatureContext->TechTalk.SpecFlow.FeatureInfo)
  Exception doesn't have a stacktrace

Steps to Reproduce

Set up with 2 classes for test hooks.

1:

        [BeforeTestRun(Order = 0)]
        private static void BeforeTestRun(IObjectContainer container, FeatureContext fContext, ScenarioContext sContext)
        {
            // stuff here
        }

2:

        [BeforeTestRun(Order = 0)]
        public static void BeforeTestRun(IObjectContainer container, FeatureContext fContext, ScenarioContext sContext)
        {
                    // stuff here
                }

If I remove the parameters from at least one of the two methods, this error does not occur.

Link to Repro Project

No response

clrudolphi commented 10 months ago

This error results from attempting to resolve the FeatureContext and/or the ScenarioContext as parameters of the BeforeTestRun hook. Those objects aren't available at that time in the sequence of execution. BoDi (SpecFlow's object container) attempts to resolve those objects using it's default object construction mechanism but it is not sophisticated enough to do that properly.

Instead, use the other hook attributes, such as BeforeFeature or BeforeScenario, that are appropriate to your situation.

HTH

ccarmannt commented 10 months ago

That's very helpful, thanks.