如何使用 Cluecumber 生成报告?

How to use Cluecumber to generate reports?

如何使用Cluecumber为自动化测试生成报告?

  1. 将 Cluecumber 插件添加到您的 pom 文件中。在撰写本文时,最新版本是 2.3.4,但可以检查 here 以获取更新。

    <plugin>
        <groupId>com.trivago.rta</groupId>
            <artifactId>cluecumber-report-plugin</artifactId>
            <version>2.3.4</version>
            <executions>
                <execution>
                    <id>report</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>reporting</goal>
                    </goals>
                </execution>
            </executions>
          <configuration>
                <sourceJsonReportDirectory>${project.build.directory}/cucumber-report</sourceJsonReportDirectory>
                <generatedHtmlReportDirectory>${project.build.directory}/generated-report
                </generatedHtmlReportDirectory>
          </configuration>
      </plugin>
    
  2. json:target/cucumber-report/cucumber.json 添加到您的 Runner,这样您就会得到如下内容:

    import io.cucumber.junit.CucumberOptions;
    import io.cucumber.junit.Cucumber;
    import org.junit.runner.RunWith;
    
    @RunWith(Cucumber.class)
    @CucumberOptions(
        features = {"."},
        glue = {"my_folder.steps", "my_folder.hooks"},
        monochrome = true,
        plugin = {"json:target/cucumber-report/cucumber.json"}
    )
    
    public class MainRunner {
    
    }
    

PS:不需要html目标

  1. 运行 你的测试,完成后导航到终端并输入 mvn cluecumber-report:reporting(完全原样)。

这将生成一个文件夹,仅当此命令为 运行 时才会出现。它将位于 target 文件夹下,名称为 generated-report。在那里你应该找到你的报告所在的 index.html 文件(右键单击并在浏览器中打开它以查看它)。