-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Make Cucumber runner extend BlockJUnit4ClassRunner #1598
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
Conversation
I'm impressed by what you've managed to do. It is unfortunately quite hacky. I mean that in the sense the concepts involved are misaligned. The As a result of this we run into quite a few complications that would make JUnit rules work quite differently from how they'd normally would be expected to work. To wit a brief list of the problem areas:
So instead of trying to push all the square pegs into round holes I think it would be better to let the user deal with it. For most cases they an do so by initializing the JUnit rule in a step definition and invoke the rules before and after methods by using Cucumbers before and after hooks. It's not quite perfect but it keeps the ambiguity out of the framework. One exception here is Spring. We currently do support Spring through the That said. I would like to be able to somewhat properly integrate JUnit Rules with Cucumber. To do so however we (much like the JUnit 5 project) would need to make our test context an explicit concept in the framework. This would require a non-trivial engineering effort. You would be most welcome to have a (collaborative) stab at it. If you would be interested in this please do hop onto the cucumber slack to discuss this. |
I was well aware that it is really a hack, just to confirm it is doable. After discussions with my colleagues, I concluded the appropriate mapping between cucumber and junit4 is as follows: Cucumber / Suite, FeatureRunner / BlockJUnit4ClassRunner, PickleRunner / FrameworkMethod. I implemented this mapping, which requires completely removing the step description feature. This does not seem to be that problematic, as it has been identified to be removed in #263 (comment) . As for the problems you identified, they are real but:
Just have a look at the pitest extension for cucumber https://github.com/alexvictoor/pitest-cucumber-plugin which contains much copy-paste to upgrade dependencies versions, whereas this improved integration between cucumber and junit brings directly the integration with pitest for no additional cost. As for using rules from the before and after hooks, not all rules allow that, as the rule design is to decorate statements. In fact, it is not possible with the spring rules. And as the cucumber-spring modules does not provide integration with the testcontextmanager, using junit rules as designed is the easiest way for me. I really hope to be able to contribute this evolution, as it effectively allows my teams to use cucumber with spring applications, mutation testing and docker containers. |
As it stands in v4 the dependency injection context is an implementation detail of the I don't find your cost argument to be particularly convincing. Your proposed changes would incur additional complexity to Cucumber to allow for functionality that has a limited application. Additionally because this functionality doesn't quite work as expected it will be a constant source of tickets, questions, confusion and complaints. It then seems only appropriate that both the cost and benefit of this functionality are in the same place. So given that you are unable to contribute to an improved spring module or an explicit test context I I would recommend that for the time being you maintain and publish your own runner. We can make this easier by reducing the amount of boiler plate needed though! Comparing |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
1 similar comment
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This is a Proof-of-Concept to improve cucumber-jam integration with junit 4 by deriving Cucumber runner from BlockJUnit4ClassRunner in order to benefit from natural integration with unit 4 features like scenario rules (#393) and natural integration with external frameworks (http://pitest.org, https://www.testcontainers.org, https://docs.spring.io/spring/docs/5.1.6.RELEASE/spring-framework-reference/testing.html#testcontext-junit4-rules)
Details
The change proven here is to derive Cucumber unit runner from BlockJUnit4ClassRunner rather than from ParentRunner, which requires in this version the make the FeatureRunner disappear to directly host scenarios/Pickles at the same level as scenarios/methods in classical unit tests.
The current implementation is really a quick and dirty proof that is can work.
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: