-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
DuplicateStepDefinition error for abstract method implementation. #2757
Comments
I'm having some trouble understanding your problem. I can not produce a duplicate |
Hi @mpkorstanje Glue objects hierarchy: Running with cucumber.xml file I'm getting:
And with maven command "clean test -Ddriver=chrome -Dmaximize=false -DsuiteXmlFile=cucumber":
|
I could reproduce the issue by adding the classes This is due to the fact that
That's interesting, I've never realized that such object-oriented construction will lead to two methods, one being an "alias" of the other. As the common Java developer, I learned this is not possible, see https://stackoverflow.com/questions/5561436/can-two-java-methods-have-same-name-with-different-return-type . But it seems I was wrong, see https://stackoverflow.com/a/5561736/698168 I see two solution variants: Ignore alias method based on
|
TL&DR: Motivation on why would need abstraction on Step definitions, this is not related to any technical aspect but rather to work methodologies and what I consider good practices. @jkronegg @mpkorstanje followed the discussion in the PR and may not be able to contribute technically to the solution but the whole motivation in making abstract implementations for "Step definitions" classes relies in the following problem, more related to a workin methodology and good practices rather than a real code problem: For common verbal expressions (used in Gherkin), where there may not exist syntactical or conceptual difference, depending on the scenario, each of this expressions in Step Definitions may change a lot in the code implementation. Usually we have the acceptance criteria to check that all the requirements are implemented but some times we can miss some points or do half implementations. Because of this, abstraction is the way that we have to enforce behaviors in OOP projects, in order to achieve this, we can use interfaces and abstract classes to enforce child classes to implement this general required behaviors, but adding the enforcement on step definition classes to also implement this behaviors, adds one layer more of compromise that this features will be applied, clearly this doesn't means that the feature files will be also enforced to implement this missing function part for common required behaviors/tests but this can be supplied with a custom plugging and even with some sort of automated script to generate feature files where we consume the already defined step definitions. Clearly if we have step definitions with the same signature, cucumber will arise the DuplicateStepDefinition exception, but we can control this using DDD sort of solution with package visibility and order (Check this blog post for more info) and this way, with package control, we could have parent classes enforcing behaviors and holding the common methods for all this classes in a parent directory. This whole discussion only makes sense in really big enterprise projects where we loss track of each one of the tickets/pages/implementations and this way we have one more tool to remember to don't miss them. |
Thanks for these clarifications.
I totally agree with you. I got the same experience on some my projects based on Cucumber: your tests are passing just because the Steps definitions are wrongly implemented. I consider steps definitions as code : they should be tested as well. Ideally, you should have a kind of test harness/framework which helps the developer. Currently, I have custom code for this. But my dream would be that Cucumber do it for you, either built-in or through a plugin (I have no idea on how to do it, but IMHO the first-in-class framework which does this is Mockito: it tells you when one of your mock is useless and guide you to write better test code). If you have ideas on how to integrate such automatic checks in Cucumber, do not hesitate to discuss the point on the Slack channel or to open a new issue on Github.
I would have done the same as proposed in the blog you mention. But without correcting the current issue, there will still be BTW, which JVM do you use ? (as this issue seems to be JVM specific) |
Currently for this project I'm using It would be nice to start checking plugging for IDE or a check for feature implementation, will start doing this investigation on my free time. The most similar thing that comes to my mind for a line by line usage check is Jacoco more usually implemented by unitary tests due to the 1-1 matching nature of unitary testing but would not be entirely wrong to do some similar kind of implementation for stepDefinitions method usage. |
No, that's not required. The issue should be resolved on Cucumber side (Cucumber should work the same way on all JVMs). |
@sanflg this issue is solved in cucumber 7.12.1 |
Problem:
Whenever we have a class with Step or Hook definition/annotation, this class cannot be inherited by another but can be the last class of an hierarchy. The problem arises when we have common methods definition across this classes and no abstract method can be implemented to enforce behaviors (abstract class nor interface). i.e:
There is any chance to made cucumber recognize abstract definitions to avoid DuplicateStepDefinition error on implementation and use POO needed implementations such as abstraction and behavior ruling?
More dependencies context: Maven
Class definitions in my scenario:
BasePageBehaviors interface
BasePage abstract class
GoogleHomePage class
Error:
The text was updated successfully, but these errors were encountered: