首页 > 解决方案 > 在日志上看不到黄瓜片段

问题描述

我刚刚启动了一个 2.1.6 版的 sping-boot 项目(使用启动器:spring-boot-starter-web、spring-boot-starter-test)

我正在尝试在 4.7.1 版中使用 cucumber for java 并使用以下 maven 依赖项:cucumber-spring、cucumber-junit、cucumber-java8。

当我启动验收测试时,我会看到日志中未定义步骤。但没有出现任何片段

所有验收测试

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "html:FeaturesReport"},
        features = {"src/test/resources/features"},
        snippets = CucumberOptions.SnippetType.UNDERSCORE)
public class AllAcceptanceTests {
}

我的情景

  Scenario: Creation from initialisation
    Given name "Jean"
    Given gender "Male"
    Given picture "picture.png"
    Given account identifier 1
    When try to create the profile with these parameters
    Then the profile id = 1 , name = "Jean" , gender = "Male" and picture = "picture.png" is saved

Junit 日志

  Scenario: Creation from initialisation                                                            # src/test/resources/features/create-profile.feature:9
    Given name "Jean"                                                                                       # ProfileSteps.java:23
    Given gender "Male"                                                                                     # ProfileSteps.java:27
    Given picture "picture.png"                                                                             # ProfileSteps.java:31
    Given account identifier 1                                                                              # null
    When try to create the profile with these parameters                                                    # ProfileSteps.java:37
    Then the profile id = 1 , name = "Jean" , gender = "Male" and picture = "picture.png" is saved # ProfileSteps.java:46

io.cucumber.junit.UndefinedThrowable: The step "existing account in nisfee-account :" is undefined

我正在使用所有 spring-boot 默认配置。我是否忘记了在我的日志中有这样的东西:

You can implement missing steps with the snippets below:

@Given("^today is Sunday$")
public void today_is_Sunday() {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

标签: javaspringspring-bootjunitcucumber

解决方案


如果您通过 JUnit 而不是 CLI 或 IDEA 运行,则必须summary显式添加插件。

@CucumberOptions(plugin = {"summary", "pretty", "html:FeaturesReport"},

推荐阅读