我已通过在FeatureStep类上添加注释来解决了此问题。
注释:
注意它上的@ActiveProfiles。
import java.lang.annotation.*;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.ActiveProfiles;import org.springframework.test.context.ContextConfiguration;@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@ContextConfiguration@ActiveProfiles("test")@SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = FeatureTestConfiguration.class)public @interface FeatureFileSteps {}配置类非常基础:
@Configuration@import(FooApplication.class)public class FeatureTestConfiguration {}使用注释:
将注释添加到功能步骤:
@FeatureFileStepspublic class FooFeatureSteps { @Given(...) @When(...) @Then(...)}现在,从我的IDE,使用maven的命令行或在构建服务器上运行Cucumber功能测试时,我的测试正在使用FooServiceSTub,并且我的测试通过了。



