-
-
Notifications
You must be signed in to change notification settings - Fork 2k
ObjectFactory in @CucumberOptions is never used. #2424
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
Comments
The default object factory will be available once #2400 is released in 7.1. No released date planned at this time. I can't reproduce your problem from the information you've provided. What I suspect that might happen is that you are not running Cucumber via JUnit but rather through IDEA which calls the command line runner. If you're looking to debug further then when using JUnit 4 the options parsing happens here, before anything else is done: cucumber-jvm/junit/src/main/java/io/cucumber/junit/Cucumber.java Lines 108 to 148 in 22378e2
And for the CLI: cucumber-jvm/core/src/main/java/io/cucumber/core/cli/Main.java Lines 55 to 76 in 22378e2
|
You are correct. Running In IDEA running a specific feature or feature file (right-click run). Does not work (it's always It doesn't seem like junit If I look at the cmd-line IDEA is passing to cucumber, the So this is a bug in the IDEA cucumber plugin? I think this hasn't come up because if you are using a loaded service, and it's the only one, that becomes the default. Which is likely what most want. How would the plugin fix this? Given a test/feature it has to examine all the stubs to find the object factory associated with the feature? And if there is more than one, run the cmd-line once for each? Thanks for the link to #2400 |
Check the run config, it allows for extra input. Everything else would be a feature request to IDEA. Though fundamentally, once you have more then one object factory you have a sufficiently complex usecase that the lack of usability is a problem for you to solve. Possibilities could be:
|
Thanks for the tips. I want to run a set of features twice, with a slightly different implementation each time, and I'm using factories to do that. I can't figure out any other way. It doesn't make any sense to make it explicit in the scenarios. It has no meaning at that level. For example in the documentation's "Is it Friday yet?" it would need to specify which time-library the app-under-test should use. The expectation is that the tests and their results won't change. I think it would be odd to put that in the scenario. And what if there is more than one library to test? Any advice on how to do this? Using a ObjectFactory is the only way I could find to pass any information between the junit stub (how I get the functions to run twice) and the step-def code. Is there another way? |
If the thing to change is the dependency on the time library implementation then consider manipulating the dependencies used. Cucumber JVM does this for the CDI implementations. With different profiles to enable/disable while developing: https://github.com/cucumber/cucumber-jvm/blob/main/jakarta-cdi/pom.xml#L103 And multiple test executions in CI: https://github.com/cucumber/cucumber-jvm/blob/main/jakarta-cdi/pom.xml#L245 |
While you can set
ObjectFactory
it is never used. You can set it to a class that isn't known by the service loader. And everything works fine.When
loadObjectFactory()
is called,this.options.getObjectFactoryClass()
always returnsnull
.at :
io.cucumber.core.runtime.ObjectFactoryServiceLoader.loadObjectFactory(ObjectFactoryServiceLoader.java:41)
If you set
ObjectFactory
the loader class just sets it to the first service returned w/o checking if the types match.If the service factory has 0 items, it works (default is set). If it has exactly 1 item, that's the factory used. Any other situation and it blows up.
I think the code that calls
loadObjectFactory()
is called before the options are parsed, which would explain whythis.options.getObjectFactoryClass()
always returns null. But that's just a guess. I dug around for a while, but the startup code is hard for me to follow.This bug exists in 7.0.0, and 6.8.1. Those are the only two versions I tried.
Using junit 4.
As a separate issue: Could DefaultFactory be public/available? If I have a custom
ObjectFactory
, but I don't want to use it for every set of tests, I need to write my own "default" for the other ones.Maybe if the iterator length > 1,
ObjectFactory
should be mandatory in every case to avoid confusion?The text was updated successfully, but these errors were encountered: