简体   繁体   English

Java/cucumber 报告不使用 masterthought 生成报告

[英]Java/cucumber reporting not producing reports using masterthought

I have been trying to integrate masterthought maven--cucumber-reporting so I can produce pretty reports on Jenkins as advertised.我一直在尝试整合 masterthought maven--cucumber-reporting这样我就可以像宣传的那样制作关于 Jenkins 的漂亮报告。 I followed the configuration instruction in various sites, including damienfremont.com posts, but my implementation does not produce any reports.我遵循了各个站点中的配置说明,包括 damienfremont.com 的帖子,但我的实现没有产生任何报告。 The similar posts on StackOverflow have not provided an answer. StackOverflow 上的类似帖子没有提供答案。

CucumberTestRunner.java CucumberTestRunner.java

@RunWith(Cucumber.class)
@CucumberOptions(
  glue = "xxx.yyy.zzz.cucumber",
  features = "src/test/resources/features",
  snippets = SnippetType.CAMELCASE,
  tags = {"@aaa", "@bbb"},
  plugin = {"json:target/cucumber.json", "html:target/site/cucumber-pretty"}
  )
public class CucumberTestRunner {}

pom.xml pom.xml

  <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>4.2.0</version>
  </dependency>

  <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.2.0</version>
  </dependency>

  <dependency>
    <groupId>net.masterthought</groupId>
    <artifactId>cucumber-reporting</artifactId>
    <version>4.4.0</version>
  </dependency>

  Other dependencies - Spring, database, logging, etc

<dependencies>

<build>
  <plugins>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.7.0</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>1.5.0</version>      
      <executions>
        <execution>
          <phase>integration-test</phase>
          <goals>
            <goal>java</goal>
          </goals>
          <configuration>
            <classpathScope>test</classpathScope>
            <mainClass>cucumber.api.cli.Main</mainClass>
            <arguments>
              <argument>--glue</argument><argument>xxx.yyy.zzz.cucumber</argument>
              <argument>--snippets</argument><argument>camelcase</argument>
              <argument>--plugin</argument><argument>html:target/cucumber.html</argument>
              <argument>src/test/resources</argument>  <!-- features location -->
            </arguments>
          </configuration>
        <\execution>
      </executions>
    </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.21.0</version>
      <configuration>
        <testFailureIgnore>true</testFailureIgnore>
      </configuration>
    </plugin>

    <plugin>
      <groupId>net.masterthought</groupId>
      <artifactId>maven--cucumber-reporting</artifactId>
      <version>4.4.0</version>      
      <executions>
        <execution>
          <id>execution</id>
          <phase>verify</phase>
          <goals>
            <goal>generate</goal>
          </goals>
          <configuration>
            <projectName>ExecuteReporting</projectname>
            <outputDirectory>${project.build.directory}/site/cucumber-reports</outputDirectory>
            <cucumberOutput>${project.build.directory}/cucumber-jason</cucumberOutput>
            <checkBuildResult>cucumber.api.cli.Main</checkBuildResult>
          </configuration>
        <\execution>
      </executions>
    </plugin>      

  </plugins>
</build>

Results: running CucumberTestRunner.java from intelliJ creates target/cucumber.json and target/site/cucumber-pretty/index.html et al结果:从 intelliJ 运行 CucumberTestRunner.java 创建 target/cucumber.json 和 target/site/cucumber-pretty/index.html 等

running mvn verify -Dcucumber.options="--tags @aaa --tags @bbb" creates target/cucumber.html/index.html et al (as specified in the pom)运行mvn verify -Dcucumber.options="--tags @aaa --tags @bbb"创建target/cucumber.html/index.html等(在 pom 中指定)

So the native surefire reports are being produced, but I'm not getting the masterthought outputs.因此正在生成本机万无一失的报告,但我没有得到 masterthought 输出。

When I run the mvn build via Jenkins, with the cucumber-reports.hfi plugin installed, I get "net.masterthought.cucumber.ValidationException: Nonereport file was added!"当我通过 Jenkins 运行mvn build ,安装了cucumber-reports.hfi插件,我得到"net.masterthought.cucumber.ValidationException: Nonereport file was added!” which makes sense since the mvn job is not producing reports.password这是有道理的,因为 mvn 作业没有生成reports.password

I have looked at other StackOverflow issues and can't see what the problem is with my code.我查看了其他 StackOverflow 问题,但看不出我的代码有什么问题。 Any help greatly appreciated.非常感谢任何帮助。

I Was Also Getting The Same Error.我也遇到了同样的错误。 Then I Used The Below Code Instead Of Using pom.xml net.masterthought Plugin.然后我使用了下面的代码而不是使用pom.xml net.masterthought插件。 It Worked And Generated The Report.它起作用并生成了报告。 But, I Was Using TestNG.但是,我使用的是 TestNG。 So, You Will Have To Check If It Works With JUnit Using @After Annotation .因此,您必须使用@After Annotation来检查它是否适用于 JUnit。

    @AfterSuite
    public void generateReport() {
    File reportOutputDirectory = new File("target"); //
    List<String> jsonFiles = new ArrayList<String>();
    jsonFiles.add("target/cucumber.json");
    String projectName = "Your Sample Project Name";
    String buildNumber = "1.0";

    Configuration configuration = new Configuration(reportOutputDirectory, 
    projectName);

    configuration.setRunWithJenkins(true);
    configuration.setBuildNumber(buildNumber);

    ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
    reportBuilder.generateReports();
}

Problem sorted : In the pom.xml , exec-maven-plugin , I needed plugin argument for json:${project.build.directory}/somewhere/for/reports问题排序:在pom.xmlexec-maven-plugin ,我需要json:${project.build.directory}/somewhere/for/reports插件参数

The fluffy Jenkins reports required the json files.蓬松的 Jenkins 报告需要 json 文件。 Also needed to ensure that the directories specified in the Jenkins Cucumber reports configuration agree with those specified in the pom.xml file.还需要确保 Jenkins Cucumber 报告配置中指定的目录与 pom.xml 文件中指定的目录一致。

Did not need the net.masterthought plugin .不需要net.masterthought plugin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM