3

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

2
  • 1
    I see the same exception. The issue is caused by the @CucumberContextConfiguration annotation you have in the base class. As a workaround, I annotated my stepDef class directly. I know it is not ideal. But solves the issue. :( Commented Apr 14, 2022 at 3:48
  • Yes, I had to do this also Commented Apr 17, 2022 at 0:21

1 Answer 1

2

In case you have several step definition classes, you can create a stub class with annotations only

@ContextConfiguration(classes = AbstractIntegrationTest.Config.class)
@CucumberContextConfiguration
public class StubConfig { }

Place it into a separate package and mention it in @CucumberOptions (if you have it) Another ugly workaround:(

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.