-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter count mismatch on optional parameter after migrating from SpecFlow #181
Comments
@BalazsSzaboElypta Wow, that is strange. Regarding my knowledge we never (officially) supported optional parameters with SpecFlow so I think it was just a lucky coincidence that that was working. Which version of SpecFlow you are migrating from? |
From |
Probably. But as I said, this was just working accidentally, so it was not a goal to keep it. Do you have many of them? Would it be possible to refactor them to ones without optional parameters? Because to be honest a proper support for that is not super easy and we anyway migrate people from regex to cucumber expressions (where such thing is not even possible), so implementing a support for optional parameters is not a strategic goal right now. |
I understand, we have around a dozen or two, so it's not the end of the world to refactor them. Probably would make the code a bit more readably as well since the regex expressions tend to get a bit complex with a lot of optional parameters. Thanks for the clarification! |
@BalazsSzaboElypta thx for the understanding. Yes, one of the motivation behind the whole cucumber expression initiative was (by the cucumber community), that the regexes could become quite complex and therefore harder to maintain. I close this issue now, but if anything comes up, feel free to reopen. |
This stackoverflow was posted/answered over 10 years ago, and then it showed that using RegEx could support optional parameters: |
Support for RegEx optional parameters seems to just be a matter of "allowing" the Match Groups regardless of the Success property. I've made these changes and did a few tests. (The commented out line "//!!!" is the original, and it's followed by the line with my change.) ...\Infrastructure\MatchArgumentCalculator.cs
...\Infrastructure\TestExecutionEngine.cs
Both of these work (as reported here https://github.com/orgs/reqnroll/discussions/288
(And, I tested more complex cases having several optional parameters and excluding ones "in the middle") |
@drosenba See discussion at #238. Based on that @olegKoshmeliuk has made the interface to override the behavior per-project (to support legacy / migration cases). Could you please try if overriding that integrace and implementing the more SpecFlow-compatibility handling way of regex groups would work for you? If yes, we could add it as a sample solution to https://docs.reqnroll.net/latest/guides/how-to-configure-cucumber-expression-behavior.html |
@gasparnagy I implemented this plugin and tested it in a small standalone app. It does work fine for the test, but the "red error squiggle" still appears in the IDE .feature file. indicating parameter count mismatch. I guess that's what you alluded to in #238 "... fix this in Visual Studio extension (code dupl!) ..."
|
My CustomArgumentCalculator above worked in the "standalone" project. But when I put it in my "SpecFlow v3 to ReqnRoll conversion" project, it's not working. It never gets to the Initialize() method. (I put in a breakpoint.) The difference between the standalone and the new / converted app is that the new app has a separate assembly that contains the Steps, Hooks, etc. and that's where I put the above CustomArgumentCalculator with the [assembly: RuntimePlugin(typeof(CustomPlugin))]. I know that my assembly is working for everything else. This is my reqnroll.json:
|
FYI, I got the above CustomArgumentCalculator plugin to work in my converted app. I was incorrect to say "difference between the standalone and the new / converted app is that the new app has a separate assembly that contains the Steps, Hooks, etc.", because the new / converted app also had the separate assembly. The difference was that the standalone app had its .feature files in that same separate assembly (class project) whereas the converted app had its .feature files in the "main program". In the end, I created a separate project/assembly just for the plugin (and named it xxxxx.ReqnrollPlugin so that it emitted xxxxx.ReqnrollPlugin.dll) and the main program has dependency on both projects (one with the Steps & Hooks, and the other the plugin.) |
Reqnroll Version
2.0.3
Which test runner are you using?
MSTest
Test Runner Version Number
3.3.1
.NET Implementation
.NET 8.0
Test Execution Method
Visual Studio Test Explorer
Content of reqnroll.json configuration file
No response
Issue Description
Before migrating to Reqnroll from Specflow a step definition using a regular expression with optional parameter (see example below) used to be working, but after migrating I get
Reqnroll.BindingException: Parameter count mismatch!
error if I don't provide the optional parameter.I didn't find any breaking change related to this in the migration documentation, so I'd expect it to be working the same (i.e. for the option parameter to be null if I don't provide a value for it in the feature file)
Steps to Reproduce
Use this step definition:
And these test cases:
Link to Repro Project
No response
The text was updated successfully, but these errors were encountered: