【问题标题】:Incorrect Test Count When running Cucumber Scenarios with Failsafe使用 Failsafe 运行 Cucumber 场景时测试计数不正确
【发布时间】:2022-11-11 16:19:46
【问题描述】:

我迷失了。我创建了一些测试(示例如下所示)并使用 Failsafe 运行它们,但计数不正确。例如,当我运行下面显示的场景时,我希望 Tests Run as 1 但它显示 2 。谁能指出我哪里出错了? 测试使用 Junit Runner 运行。

设想:-

  @QA-100 @abc @xyz
  Scenario: Generation of xml file
    Given I have generated a xml file with below details
      | empname| department| 
      | Jordan | Accounts  | 
Then I am able to see the details in the file

来自“构建”部分的 pom 的一部分:-

<build>
<plugins>
  <plugin>
    <groupId>net.masterthought</groupId>
    <artifactId>maven-cucumber-reporting</artifactId>
    <version>2.8.0</version>
    <executions>
      <execution>
        <id>execution</id>
        <phase>verify</phase>
        <goals>
          <goal>generate</goal>
        </goals>
        <configuration>
          <projectName>Cucumber Report</projectName>
          <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
          <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
        </configuration>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven.surefire.version}</version>
    <configuration>
      <skip>true</skip>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>${maven.failsafe.version}</version>
    <dependencies>
      <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-junit4</artifactId>
        <version>${maven.surefire.version}</version>
      </dependency>
    </dependencies>
    <configuration>
      <includes>
        <include>**/${test}.*</include>
      </includes>
      <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
      <systemPropertyVariables>
        <configFile>${config}</configFile>
      </systemPropertyVariables>
    </configuration>
    <executions>
      <execution>
        <goals>
          <goal>integration-test</goal>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${maven.compiler.version}</version>
    <configuration>
      <encoding>UTF-8</encoding>
      <source>${java.source.version}</source>
      <target>${java.target.version}</target>
      <fork>true</fork>
      <meminitial>4096m</meminitial>
      <maxmem>8192m</maxmem>
    </configuration>
  </plugin>
</plugins>

运行测试的 Maven 命令:-

 mvn clean verify -Dtest=RunTest -Dconfig=local '-Dcucumber.filter.tags=@abc' 

故障安全摘要 xml 在测试运行后具有以下详细信息:-

    <completed>2</completed>
    <errors>0</errors>
    <failures>0</failures>
    <skipped>0</skipped>

故障安全和万无一失的版本:-

 <maven.failsafe.version>2.22.2</maven.failsafe.version>
 <maven.surefire.version>2.22.2</maven.surefire.version> 
  <junit.version>4.13.2</junit.version>
    <cucumber.version>6.11.0</cucumber.version>
    <maven.compiler.version>3.8.1</maven.compiler.version

控制台中的测试运行结果:-

[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

【问题讨论】:

    标签: maven cucumber junit4 maven-surefire-plugin maven-failsafe-plugin


    【解决方案1】:

    您没有提供足够的信息来重现您的问题。

    但是,创建此问题的一种方法是执行以下操作:

    1. 将您的功能保留在src/test/resources 下
    2. 运行mvn test
    3. 重命名功能文件
    4. 再次运行mvn test。

      在步骤 #2 中,Maven 已将所有资源复制到 target 文件夹。在步骤 #3 中,它将重命名的功能文件复制到 target 文件夹。因此,您现在在 target 文件夹中拥有原始和重命名的功能文件。所以在运行测试时,两个特性文件都会被执行。

      重命名文件后尝试运行mvn clean test 来清理target 文件夹。

    【讨论】:

    • 谢谢。我现在已经用更多细节更新了这个问题。
    • 目前,如果你从一个空项目开始,只有这篇文章,你能创建自己的问题吗?
    • 让我检查一个空项目
    猜你喜欢
    • 1970-01-01
    • 2021-06-16
    • 2020-01-03
    • 2020-07-13
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    相关资源
    最近更新 更多