question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mpkorstanjecommented, Jan 20, 2022

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.

0reactions
Serkan80commented, Sep 20, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test class should have exactly one public zero-argument ...
I had this issue when I imported the wrong Test class. While a constructor was using JUnit 5 features, I imported the old...
Read more >
New DefaultObjectFactory from 7.1.0 can't instantiate bean for ...
io.cucumber.core.exception.CucumberException : class *ClassWithSteps* does not have a public zero-argument constructor.
Read more >
Test class should have exactly one public zero-argument ...
My existing test was parameterized and looked something like ... JUnit: Test class should have exactly one public zero-argument constructor.
Read more >
Test class should have exactly one public constructor
Hi, I'm having a strange issue when running one of my tests, I get the exception: java.lang.Exception: Test class should have exactly one ......
Read more >
PicoContainer Doesn't Support Zero-Argument Constructors ...
A little gotcha around using PicoContainer (with Cucumber) where it may not be usable.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found