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.

[Spring] CucumberBackendException: No qualifying bean of type

See original GitHub issue

When trying to run step defs with abstract class contains all the context configuration spring sees 2 differnt beans parent and stepdef

I’m using spring boot version: 2.6.4 , with Junit 5 and cucumber version 7.2.3

@SpringBootTest(classes = CoreApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(classes = AbstractIntegrationTest.Config.class)
@CucumberContextConfiguration
public abstract class AbstractIntegrationTest implements En {}

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("com/example/bdd")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example.bdd")
public class CucumberIntegrationTest {
}

public class MyStepdefs extends AbstractIntegrationTest{

    public MyStepdefs() {
        When("^client post to \"([^\"]*)\" with valid data$", (String arg0) -> {
        });
        Then("^the client receives status code of (\\d+)$", (Integer arg0) -> {
        });
    }
}

Exception Stack trace:

io.cucumber.core.backend.CucumberBackendException: No qualifying bean of type 'com.orange.ces.core.bdd.AbstractIntegrationTest' available: expected single matching bean but found 2: com.orange.ces.core.bdd.MyStepdefs,com.orange.ces.core.bdd.AbstractIntegrationTest
	at io.cucumber.spring.TestContextAdaptor.notifyTestContextManagerAboutAfterTestMethod(TestContextAdaptor.java:124)
	at io.cucumber.spring.TestContextAdaptor.stop(TestContextAdaptor.java:107)
	at io.cucumber.spring.SpringFactory.stop(SpringFactory.java:161)
	at io.cucumber.core.runner.Runner.disposeBackendWorlds(Runner.java:156)
	at io.cucumber.core.runner.Runner.runPickle(Runner.java:78)
	at io.cucumber.core.runtime.Runtime.lambda$executePickle$6(Runtime.java:128)
	at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$3(CucumberExecutionContext.java:151)
	at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23)
	at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:151)
	at io.cucumber.core.runtime.Runtime.lambda$executePickle$7(Runtime.java:128)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at io.cucumber.core.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:249)
	at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)
	at io.cucumber.core.runtime.Runtime.lambda$runFeatures$3(Runtime.java:110)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
	at java.base/java.util.stream.SliceOps$1$1.accept(SliceOps.java:199)
	at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1632)
	at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
	at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
	at io.cucumber.core.runtime.Runtime.runFeatures(Runtime.java:111)
	at io.cucumber.core.runtime.Runtime.lambda$run$0(Runtime.java:82)
	at io.cucumber.core.runtime.Runtime.execute(Runtime.java:94)
	at io.cucumber.core.runtime.Runtime.run(Runtime.java:80)
	at io.cucumber.core.cli.Main.run(Main.java:87)
	at io.cucumber.core.cli.Main.main(Main.java:30)
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.orange.ces.core.bdd.AbstractIntegrationTest' available: expected single matching bean but found 2: com.orange.ces.core.bdd.MyStepdefs,com.orange.ces.core.bdd.AbstractIntegrationTest
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1271)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:494)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:349)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1172)
	at io.cucumber.spring.TestContextAdaptor.notifyTestContextManagerAboutAfterTestMethod(TestContextAdaptor.java:120)
	... 30 more

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mpkorstanjecommented, Apr 10, 2022

I wouldn’t be able to say that with certainty. You’d have to sprinkle some break points around in the SpringFactory and take a look.

0reactions
mpkorstanjecommented, Apr 26, 2022

I’m going to say that using:

@CucumberContextConfiguration
public abstract class AbstractIntegrationTest implements En {}

isn’t supported, there should be a single concrete instance of an @CucumberContextConfiguration annotated class for each test execution. And with #2174 I don’t see much reason to improve the usability or errors messages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CucumberBackendException: No qualifying bean of type
When trying to run step defs with abstract class contains all the context configuration spring sees 2 differnt beans parent and stepdef.
Read more >
CucumberException No qualifying bean of type x is defined
I know that this is essentially a Spring exception but, as I mentioned, this configuration works fine when Cucumber 1.1.8 is set and...
Read more >
No qualifying bean of type-Springboot - appsloveworld.com
[Solved]-CucumberBackendException: No qualifying bean of type-Springboot ... Place it into a separate package and mention it in @CucumberOptions (if you have it) ...
Read more >
NoUniqueBeanDefinitionExcepti...
NoUniqueBeanDefinitionException: No qualifying bean of type available: expected single matching bean but found 2: The spring boot exception org.
Read more >
Developers - [Spring] CucumberBackendException: No qualifying ...
[Spring] CucumberBackendException: No qualifying bean of type.
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