当前位置: 首页 > 知识库问答 >
问题:

CucumberBackendException:没有类型的合格bean

秋兴思
2023-03-14

当试图用包含所有上下文配置的抽象类运行stepdefs时,spring看到2个不同的beans parent和step def

我使用的是Spring Booking版本:2.6.4,JUnit 5和Cucumber版本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) -> {
        });
    }
}

异常堆栈跟踪:

io.cucumber.core.runtime.CucumberExecutionContext.runTestCase:没有可用的“CucumberExecutionContext.java:151”类型的合格bean:预期的单个匹配bean,但发现2:io.cucumber.core.runtime.Runtime.lambda,Runtime.java:128在java.base/java.util.concurrent.Executors(RunnableAdapter.call)在Executors.java:515(java.base/java.util.concurrent.FutureTask.run)在FutureTask.java:264(io.cucumber.core.runtime.Runtime)在SameThreadExecutorService.execute(Runtime.java:249)在io.cucumber.core.runner.Runner.runPickle(Runner.java:78)在io.cucumber.core.runtime.Runtime.lambda美元执行选择6美元(Runtime.java:128)在io.cucumber.core.runtime.CucumberExecutionContext.lambda美元runTestCase3美元(CucumberExecutionContext.java:151)在io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23)在io.cucumber.core.backend.CucumberBackendException(com.orange.ces.core.bdd.AbstractIntegrationTest)在com.orange.ces.core.bdd.MyStepdefs美元执行选择7美元(com.orange.ces.core.bdd.AbstractIntegrationTest)在io.cucumber.spring.TestContextAdaptor.notifyTestContextManagerAboutAfterTestMethod美元TestContextAdaptor.java:124(io.cucumber.spring.TestContextAdaptor.stop)在TestContextAdaptor.java:107(io.cucumber.spring.SpringFactory.stop)在SpringFactory.java:161美元io.cucumber.core.runner.Runner.disposeBackendWorlds(Runner.java:156)在io. cucumber. core. runtime. Runtime. lambda$runFeatures3美元(Runtime. java: 110)在java. base/java. util. stream. Re在java. base/java. util. java. SliceOps1美元1美元1美元接受(SliceOps. java: 199)在java. base/java. util. java: 195)474)在java. base/java. util. stream. RedueOps$RedueOps.在io. cucumber. core. runtime. Runtime. Runtime. RunFeature(Runtime. java: 111)在java. base/java. util. stream. AbstractPipeline. java: 234)在io. cucumber. core. runtime. Runtime. Runtime. lambda在io. cucumber. core. runtime. Runtime. Runtime. lambda运行0美元(Runtime. java: 82)在io. cucumber. core. runtime. Runtime.运行时.执行(Runtime. java: 94)在io. cucumber. core. runtime. run(Runtime. java: 80)

共有1个答案

庞乐池
2023-03-14

如果您有多个步骤定义类,则可以创建一个只包含注释的存根类

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

将其放入一个单独的包中并在@CucumberOptions中提及(如果您有它)另一个丑陋的解决方法:(

 类似资料: