Java 如何使用导入库中的Cumber step类?

Java 如何使用导入库中的Cumber step类?,java,cucumber,cucumber-java,cucumber-spring,Java,Cucumber,Cucumber Java,Cucumber Spring,我制作了一个java lib项目,其中包含所有步骤类,可用于其他项目 package ulala.aop.integration.steps; public class KafkaSteps { @Autowired private BinderAwareChannelResolver resolver; @Autowired private MessageChannel localOutput, throttlingOutput; @Autowired private Applicat

我制作了一个java lib项目,其中包含所有步骤类,可用于其他项目

package ulala.aop.integration.steps;

public class KafkaSteps {

@Autowired
private BinderAwareChannelResolver resolver;

@Autowired
private MessageChannel localOutput, throttlingOutput;

@Autowired
private ApplicationContext applicationContext;

private MessageBuilder messageBuilder;

private MessageChannel messageChannel;

private String message;

@Given("{string} topic destination to notify")
public void kafkaServerWithTopic(String destination) {

    messageChannel = resolver.resolveDestination(destination);

}
...
配置如下所示

package ulala.aop.integration.boot;
@SpringBootTest
@AutoConfigureMockMvc
@CucumberContextConfiguration
public class CucumberConfiguration {
}
我添加了对主spring引导项目的依赖。该项目有一个rest控制器,具有以下功能

在rest类上,我执行如下特性

String response = String.valueOf(Main.run(new String[]{"--glue",
                        "ulala.aop.integration.steps",
                        "classpath:features/local/notify.feature"}
                , Thread.currentThread().getContextClassLoader()));
其特点如下:

Scenario: Notify on kafka
  Given "integration.test.in" topic destination to notify
  Then add message to notify
    |   field      |    value     |
    | test field   | value field  |
  And add header "headerTest" with value "integration.header"
  And notify kafka
我得到一个nullpointerexception

    This fallback has beep deprecated. Please annotate a glue class with some context configuration.

For example:

   @@CucumberContextConfiguration
   @SpringBootTest(classes = TestConfig.class)
   public class CucumberSpringConfiguration { }
Or: 

   @@CucumberContextConfiguration
   @ContextConfiguration( ... )
   public class CucumberSpringConfiguration { }
F---

Failed scenarios:
classpath:features/local/notify.feature:17# Notify on kafka

1 Scenarios (1 failed)
4 Steps (1 failed, 3 skipped)
0m0.105s


java.lang.NullPointerException
    at pnc.aop.integration.steps.KafkaSteps.kafkaServerWithTopic(KafkaSteps.java:38)

你的
CucumberConfiguration
类在?@M.P.Korstanje
ulala.aop.integration.boot
到lib项目中是什么包你将哪个包作为胶水传递?@M.P.Korstanje功能在主项目中,步骤在外部lib上。以下代码位于主项目
新字符串[]{--glue”,“ulala.aop.integration.steps”,“classpath:features/local/notify.feature”}
配置和步骤都必须位于glue路径上。您只能指定一个。