Skip to content

class *ClassWithSteps* does not have a public zero-argument constructor #2469

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

Closed
ralphavalon opened this issue Jan 20, 2022 · 6 comments
Closed

Comments

@ralphavalon
Copy link

Describe the bug
After upgrading from 7.0.0 to any version from 7.1.0 to 7.2.3, the following error occurs when trying to run Cucumber through io.cucumber.core.cli.Main. It's basically the same problem mentioned in #2431 , but now with a reproducible example.

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
 * ...etc

To Reproduce
Steps to reproduce the behavior:

  1. Clone this project: https://github.com/ralphavalon/cucumber-issue
  2. Build it ( docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3-adoptopenjdk-15 mvn clean package )
  3. Run it ( docker run -v "$PWD":/home -w /home openjdk:15-jdk java -jar target/demo-0.0.1-SNAPSHOT-fat-testjar.jar )

Expected behavior
The expected behavior is to run the tests with no error, as it happens when you change cucumber version to 7.0.0 in the reproducible example.

Context & Motivation

While upgrading libraries to the latest to stay up-to-date, faced this issue and stopped this upgrade.

Environment

On the reproducible example:

Cucumber version: 7.2.2
Java 15
Maven 3.6.1
Used modules: cucumber-java, cucumber-core, cucumber-junit, cucumber-picocontainer

Additional context
On the reproducible example it's generated a jar through the assembly plugin that should run the cucumber command.

Let me know if you need any more information.

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Jan 20, 2022

Without executing the reproducer I reckon the assembly plugin is clobbering the META-INF/services/io.cucumber.core.backend.ObjectFactory files from cucumber-core and cucumber-pico and I do not see any Container Descriptor Handlers in the assembly that would prevent this.

Consider adding the metaInf-services container descriptor handler.

@ralphavalon
Copy link
Author

I will try that and get back to you. I didn't see something about it on 7.1.0 release notes and it wouldn't explain why it doesn't fail with 7.0.0

There is a descriptor file (https://github.com/ralphavalon/cucumber-issue/blob/main/assembly-fat-testjar.xml) but since it doesn't have the containerDescriptorHandlers tag, I'll test it.

@mpkorstanje
Copy link
Contributor

I didn't see something about it on 7.1.0 release notes and it wouldn't explain why it doesn't fail with 7.0.0

That would be caused by #2400 which added the META-INF/services/io.cucumber.core.backend.ObjectFactory to cucumber-core. Previously you'd only receive that file from cucumber-pico.

I wouldn't really consider building fat-jars part of the public API, but feel free to send a PR that adds a note to the changelog.

@ralphavalon
Copy link
Author

It fixes the issue indeed (consider it closed), which leads me to the (probably dumb) question: if it should be the default object factory, why do I need to explicitly say it, if I'm not overriding it?

Anyway, thanks for your time. I'll close the issue.

@mpkorstanje
Copy link
Contributor

There is a use case where people use Cucumber both for unit tests and integration tests. The unit tests are ran without any dependency injection and the integration tests with a spring application context. Because the application context be slow to start, it may be undesirable to use for unit tests. Hence the usecase to select the default object factory even when other object factories are available.

This is unrelated to your problem though.

Your problem was caused by merging two different jar files into a single jar file. If any file names overlap, only the contents from one of the two jars will be used. As a result Cucumber could only see one of the two object factories. This happened to be the default object factory rather then pico container.

@Serkan80
Copy link

what is the solution for this problem ? It's not really clear what to do exactly. If there is a breaking change and extra configuration is needed, plz mention this also in the documentation.

Now I'm having the same problem. I upgraded Cucumber to the latest version 7.5.x and I have the cucumber-picocontainer as a dependency in my pom.xml and I'm getting the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants