class *ClassWithSteps* does not have a public zero-argument constructor
See original GitHub issueDescribe 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:
- Clone this project: https://github.com/ralphavalon/cucumber-issue
- Build it (
docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3-adoptopenjdk-15 mvn clean package
) - 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.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
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.
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.