简体   繁体   English

SerenityBDD 并行测试执行不起作用

[英]SerenityBDD parallel test execution is not working

I am unable to run serenityBDD tests in parallel.我无法并行运行 serenityBDD 测试。 Project is with 3 modules with standard steps(test/java/steps) and feature files(test/java/resources/feature_files) locations for api and ui modules.项目包含 3 个模块,其中包含用于 api 和 ui 模块的标准步骤(test/java/steps)和功能文件(test/java/resources/feature_files)位置。 Everything works fine but with given pom file I am expecting tests to run parallel at feature files level but tests are being executed serially.一切正常,但对于给定的 pom 文件,我希望测试在功能文件级别并行运行,但测试是串行执行的。 I have referred this blog any help please?我已经提到这个博客有什么帮助吗?

  • api应用程序接口
  • common常见的
  • ui用户界面

main pom.xml主 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <artifactId>demo-automation</artifactId>
  <description>demo-automation</description>
  <groupId>demo-automation</groupId>
  <name>demo-automation</name>
  <packaging>pom</packaging>
  <modelVersion>4.0.0</modelVersion>
  <modules>
    <module>common</module>
    <module>api</module>
    <module>ui</module>
  </modules>

  <parent>
    <artifactId>spring-boot-starter-parent</artifactId>
    <groupId>org.springframework.boot</groupId>
    <relativePath/>
    <version>2.7.5</version> <!-- lookup parent from repository -->
  </parent>

  <properties>
    <encoding>UTF-8</encoding>
    <java.version>1.8</java.version>
    <junit.jupiter.version>5.8.2</junit.jupiter.version>
    <junit.vintage.version>5.8.2</junit.vintage.version>
    <maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.failsafe.plugin.version>3.0.0-M5</maven.failsafe.plugin.version>
    <maven.surefire.plugin.version>3.0.0-M5</maven.surefire.plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <rest.version>4.2.1</rest.version>
    <selenium.version>4.1.1</selenium.version>
    <serenity.cucumber.version>3.2.3</serenity.cucumber.version>
    <serenity.version>3.2.3</serenity.version>
    <tags/>
    <version>${project.version}</version>
  </properties>
  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <name>bintray-plugins</name>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <url>https://jcenter.bintray.com</url>
    </pluginRepository>
  </pluginRepositories>

  <repositories>
    <repository>
      <id>central</id>
      <name>bintray</name>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <url>https://jcenter.bintray.com</url>
    </repository>
    <repository>
      <id>maven_central</id>
      <name>Maven Central</name>
      <url>https://repo.maven.apache.org/maven2/</url>
    </repository>
  </repositories>
  <version>1.0-SNAPSHOT</version>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <groupId>org.apache.maven.plugins</groupId>
        <version>3.8.1</version>
      </plugin>

      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
        <groupId>org.apache.maven.plugins</groupId>
        <version>${maven.surefire.plugin.version}</version>
      </plugin>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <includes>
            <include>**/TestRunner*.java</include>
          </includes>
          <systemPropertyVariables>
            <tags/>
            <webdriver.base.url/>
          </systemPropertyVariables>
          <parallel>methods</parallel>
          <threadCount>4</threadCount>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
        <version>${maven.failsafe.plugin.version}</version>
      </plugin>
      <plugin>
        <artifactId>serenity-maven-plugin</artifactId>
        <configuration>
          <reports>single-page-html</reports>
          <tags>${tags}</tags>
        </configuration>
        <dependencies>
          <dependency>
            <artifactId>serenity-single-page-report</artifactId>
            <groupId>net.serenity-bdd</groupId>
            <version>${serenity.version}</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <goals>
              <goal>aggregate</goal>
            </goals>
            <id>serenity-reports</id>
            <phase>post-integration-test</phase>
          </execution>
        </executions>
        <groupId>net.serenity-bdd.maven.plugins</groupId>
        <version>${serenity.version}</version>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
        <groupId>org.apache.maven.plugins</groupId>
      </plugin>
    </plugins>

    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>

  </build>
  <dependencies>
    <dependency>
      <artifactId>spring-boot-starter</artifactId>
      <groupId>org.springframework.boot</groupId>
    </dependency>
    <dependency>
      <artifactId>lombok</artifactId>
      <groupId>org.projectlombok</groupId>
      <optional>true</optional>
    </dependency>
    <!-- JUnit 5 -->
    <dependency>
      <artifactId>junit-jupiter-engine</artifactId>
      <groupId>org.junit.jupiter</groupId>
      <scope>test</scope>
      <version>${junit.jupiter.version}</version>
    </dependency>
    <dependency>
      <artifactId>junit-vintage-engine</artifactId>
      <groupId>org.junit.vintage</groupId>
      <scope>test</scope>
      <version>${junit.vintage.version}</version>
    </dependency>
    <!-- Serenity -->
    <dependency>
      <artifactId>serenity-core</artifactId>
      <groupId>net.serenity-bdd</groupId>
      <scope>test</scope>
      <version>${serenity.version}</version>
    </dependency>
    <dependency>
      <artifactId>serenity-cucumber</artifactId>
      <groupId>net.serenity-bdd</groupId>
      <scope>test</scope>
      <version>${serenity.cucumber.version}</version>
    </dependency>
    <dependency>
      <artifactId>serenity-junit</artifactId>
      <groupId>net.serenity-bdd</groupId>
      <version>${serenity.version}</version>
    </dependency>
    <dependency>
      <artifactId>maven-failsafe-plugin</artifactId>
      <groupId>org.apache.maven.plugins</groupId>
      <type>maven-plugin</type>
      <version>3.0.0-M5</version>
    </dependency>
    <dependency>
      <artifactId>commons-lang3</artifactId>
      <groupId>org.apache.commons</groupId>
    </dependency>
    <dependency>
      <artifactId>jackson-databind</artifactId>
      <groupId>com.fasterxml.jackson.core</groupId>
    </dependency>
    <dependency>
      <artifactId>spring-retry</artifactId>
      <groupId>org.springframework.retry</groupId>
      <scope>test</scope>
      <version>1.2.5.RELEASE</version>
    </dependency>
    <dependency>
      <artifactId>serenity-spring</artifactId>
      <groupId>net.serenity-bdd</groupId>
      <scope>test</scope>
      <version>3.5.0</version>
    </dependency>
    <dependency>
      <artifactId>spring-boot-test</artifactId>
      <groupId>org.springframework.boot</groupId>
    </dependency>
    <dependency>
      <artifactId>httpcore</artifactId>
      <groupId>org.apache.httpcomponents</groupId>
      <scope>test</scope>
      <version>4.4.15</version>
    </dependency>
    <dependency>
      <artifactId>serenity-rest-assured</artifactId>
      <exclusions>
        <exclusion>
          <artifactId>rest-assured</artifactId>
          <groupId>io.rest-assured</groupId>
        </exclusion>
      </exclusions>
      <groupId>net.serenity-bdd</groupId>
      <version>${serenity.version}</version>
    </dependency>
    <dependency>
      <artifactId>rest-assured</artifactId>
      <groupId>io.rest-assured</groupId>
      <version>${rest.version}</version>
    </dependency>
    <dependency>
      <artifactId>xml-path</artifactId>
      <groupId>io.rest-assured</groupId>
      <version>${rest.version}</version>
    </dependency>
    <dependency>
      <artifactId>json-path</artifactId>
      <groupId>io.rest-assured</groupId>
      <version>${rest.version}</version>
    </dependency>
    <dependency>
      <artifactId>json-schema-validator</artifactId>
      <groupId>io.rest-assured</groupId>
      <version>${rest.version}</version>
    </dependency>
    <dependency>
      <artifactId>cucumber-java</artifactId>
      <groupId>io.cucumber</groupId>
      <version>7.2.3</version>
    </dependency>
    <dependency>
      <artifactId>spring-boot-starter-test</artifactId>
      <exclusions>
        <exclusion>
          <artifactId>android-json</artifactId>
          <groupId>com.vaadin.external.google</groupId>
        </exclusion>
      </exclusions>
      <groupId>org.springframework.boot</groupId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <artifactId>spring-rabbit</artifactId>
      <groupId>org.springframework.amqp</groupId>
      <version>2.4.2</version>
    </dependency>
    <dependency>
      <artifactId>logback-classic</artifactId>
      <groupId>ch.qos.logback</groupId>
      <version>1.2.10</version>
    </dependency>
    <dependency>
      <artifactId>commons-io</artifactId>
      <groupId>commons-io</groupId>
      <version>2.11.0</version>
    </dependency>

    <dependency>
      <artifactId>jackson-core</artifactId>
      <groupId>com.fasterxml.jackson.core</groupId>
      <version>2.13.1</version>
    </dependency>
    <dependency>
      <artifactId>jackson-annotations</artifactId>
      <groupId>com.fasterxml.jackson.core</groupId>
      <version>2.13.1</version>
    </dependency>

    <dependency>
      <artifactId>assertj-core</artifactId>
      <groupId>org.assertj</groupId>
      <scope>test</scope>
      <version>3.22.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
    <dependency>
      <artifactId>commons-cli</artifactId>
      <groupId>commons-cli</groupId>
      <version>1.5.0</version>
    </dependency>
  </dependencies>

</project>

And ui pox.xml,和 ui pox.xml,

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://maven.apache.org/POM/4.0.0"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <name>ui</name>
  <artifactId>ui</artifactId>
  <parent>
    <artifactId>demo-automation</artifactId>
    <groupId>demo-automation</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
        <groupId>org.apache.maven.plugins</groupId>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <groupId>org.apache.maven.plugins</groupId>
        <version>2.19.1</version>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
        <groupId>org.apache.maven.plugins</groupId>
        <version>3.8.1</version>
      </plugin>

      <plugin>
        <artifactId>jsonschema2pojo-maven-plugin</artifactId>
        <configuration>
          <sourceDirectory>${basedir}/src/test/resources/schema</sourceDirectory>
          <sourceType>json</sourceType>
          <targetPackage>demo.ui</targetPackage>
          <useCommonsLang3>true</useCommonsLang3>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
        <groupId>org.jsonschema2pojo</groupId>
        <version>0.4.34</version>
      </plugin>

      <plugin>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <configuration>
              <sources>
                <source>>${basedir}/target/java-gen</source>
              </sources>
            </configuration>
            <goals>
              <goal>add-source</goal>
            </goals>
            <id>test</id>
            <phase>generate-sources</phase>
          </execution>
        </executions>
        <groupId>org.codehaus.mojo</groupId>
        <version>1.4</version>
      </plugin>
    </plugins>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
  </build>
  <dependencies>
    <dependency>
      <artifactId>common</artifactId>
      <groupId>demo-automation</groupId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <artifactId>serenity-screenplay</artifactId>
      <groupId>net.serenity-bdd</groupId>
      <scope>test</scope>
      <version>${serenity.version}</version>
    </dependency>
    <dependency>
      <artifactId>serenity-screenplay-webdriver</artifactId>
      <groupId>net.serenity-bdd</groupId>
      <scope>test</scope>
      <version>${serenity.version}</version>
    </dependency>
    <dependency>
      <artifactId>serenity-ensure</artifactId>
      <groupId>net.serenity-bdd</groupId>
      <scope>test</scope>
      <version>${serenity.version}</version>
    </dependency>
  </dependencies>
</project>

Looks like you are indirectly running Serenity through the junit-vintage-engine .看起来您正在通过junit-vintage-engine间接运行 Serenity。 When executed this way, parallel execution is simply not supported.以这种方式执行时,根本不支持并行执行。

To be exact you are running your tests through Surefire -> JUnit 5 -> JUnit Vintage -> JUnit 4 -> Serenity -> Cucumber.确切地说,您正在通过 Surefire -> JUnit 5 -> JUnit Vintage -> JUnit 4 -> Serenity -> Cucumber 运行测试。

You'd have to wait for JUnit Vintage to support parallel execution or get rid of JUnit 5 from your depencies so Surefire can run JUnit 4 directly.您必须等待 JUnit Vintage 支持并行执行或从依赖项中删除 JUnit 5,以便 Surefire 可以直接运行 JUnit 4。

However given that you are also using Spring you may not be able to get rid of JUnit 5.然而,鉴于您也在使用 Spring,您可能无法摆脱 JUnit 5。

You could ask Serenity to support JUnit 5 but I suspect they will be unable too.您可以要求 Serenity 支持 JUnit 5,但我怀疑他们也做不到。 They have never bothered to contribute the extension points they'd need upstream.他们从不费心去贡献他们需要的上游扩展点。 Instead they have hacked their stuff into Cucumber.相反,他们将自己的东西黑进了 Cucumber。

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

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