Skip to content
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

New DefaultObjectFactory from 7.1.0 can't instantiate bean for steps definitions class #2431

Closed
jpalaz opened this issue Dec 3, 2021 · 2 comments
Labels
🍼 incomplete Blocked until more information is provided

Comments

@jpalaz
Copy link

jpalaz commented Dec 3, 2021

Describe the bug
Up to 7.0.0 my StepsDefinitions class is working fine with spring injection. But after updating to 7.1.0 I've started getting the following error:

io.cucumber.core.exception.CucumberException: class *ClassWithSteps* does not have a public zero-argument constructor.
To use dependency injection add an other ObjectFactory implementation such as:
 * cucumber-picocontainer
 * cucumber-spring
 * cucumber-jakarta-cdi
 * ...ect
	at io.cucumber.core.backend.DefaultObjectFactory.cacheNewInstance(DefaultObjectFactory.java:57)
...

To Reproduce

  1. Steps definitions class looks like the following one:
@RequiredArgsConstructor
@CucumberContextConfiguration
@ContextConfiguration(classes = TestConfig.class)
public class ClassWithSteps {

private final SomeService1 injectedService1;
private final SomeService2 injectedService2;

// ... all @Given, @When, @Then methods
}
  1. Tests get running through the TestRunner class annotated with @RunWith(Cucumber.class) and @CucumberOptions.

Context & Motivation
I see recently merged PR #2400. And want to know if I have a bad config now regarding this newly added DefaultObjectFactory? Or is there an issue with DefaultObjectFactory itself?

Environment

  • Cucumber version: 7.1.0
  • Java 11
  • Maven 3.6.1
  • Used modules: cucumber-java, cucumber-junit, cucumber-spring
  • spring 5.3.13

@mpkorstanje

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Dec 3, 2021

I would expect this problem to show up in the spring example module. So I think this may be on your end.

Cucumber uses Javas SPI to discover object factories. See: https://github.com/cucumber/cucumber-jvm/blob/main/core/src/main/java/io/cucumber/core/runtime/ObjectFactoryServiceLoader.java

Are you running from an executable jar? If so you may be clobbering the service description when unpacking and merging jar files.

Either way can you debug the ObjectFactoryServiceLoader to describe the problem in sufficient detail or provide a minimal reproducer in the form of a GitHub repo?

@mpkorstanje
Copy link
Contributor

We can reopen this once more information is provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍼 incomplete Blocked until more information is provided
Projects
None yet
Development

No branches or pull requests

2 participants