【发布时间】:2020-05-28 16:19:30
【问题描述】:
我正在尝试设置 serenity cucumber 测试以并行运行
我已经添加了所有提到的必要配置,但由于某些原因,测试在单个线程中执行。我尝试了 forkCount、threadCount、parallel、useUnlimitedThreadCounts 等的各种组合,但似乎没有任何效果。
还尝试了对 JUnit 4 和 5 的依赖,但效果不佳。
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
<serenity.version>2.2.5</serenity.version>
<serenity.maven.version>2.2.5</serenity.maven.version>
<serenity.cucumber5.version>2.2.2</serenity.cucumber5.version>
<cucumber.version>5.6.0</cucumber.version>
<selenium.version>3.141.59</selenium.version>
</properties>
<dependencies>
<!-- Cucumber -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<!-- Serenity -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
<exclusions>
<exclusion>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber5</artifactId>
<version>${serenity.cucumber5.version}</version>
</dependency>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M4</version>
</dependency>
</dependencies>
<configuration>
<parallel>classes</parallel>
<threadCount>2</threadCount>
<forkCount>2C</forkCount>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
验证的 maven 调试日志表明 parallelMavenExecution 出于某种原因设置为 false。
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M4:integration-test from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M4, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@4f8e5cde]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M4:integration-test' with basic configurator -->
[DEBUG] (s) additionalClasspathElements = []
[DEBUG] (s) basedir = /Users/vinothraj/IdeaProjects/hiscox-usa-portal-testsuite
[DEBUG] (s) childDelegation = false
[DEBUG] (s) classpathDependencyExcludes = []
[DEBUG] (s) defaultClassesDirectory = /target/classes
[DEBUG] (s) dependenciesToScan = []
[DEBUG] (s) disableXmlReport = false
[DEBUG] (s) enableAssertions = true
[DEBUG] (f) excludedEnvironmentVariables = []
[DEBUG] (f) forkCount = 2C
[DEBUG] (s) forkMode = once
[DEBUG] (s) forkedProcessExitTimeoutInSeconds = 30
[DEBUG] (s) junitArtifactName = junit:junit
[DEBUG] (s) localRepository = id: local
url: file:///.m2/repository/
layout: default
snapshots: [enabled => true, update => always]
releases: [enabled => true, update => always]
[DEBUG] (s) parallel = classes
[DEBUG] (f) parallelMavenExecution = false
[DEBUG] (s) parallelOptimized = true
[DEBUG] (s) perCoreThreadCount = true
提前致谢。
【问题讨论】:
-
首先从 maven-surefire-plugin 中删除
surefire-junit47。此外,如果我没有记错黄瓜的文档,它只支持 JUnit 4,这意味着您必须至少在项目中添加对 junit 4 的依赖项。 -
@khmarbaise - 由于帖子中的答案,我添加了万无一失。 stackoverflow.com/questions/19716619/… 我对 4.12 有 JUNIT 依赖项。谢谢
-
首先提到的帖子已有 7 年历史,并且在撰写本文时是错误的(与提供者有依赖关系?等等。问题是关于并行化)。 JUnit 4.12 依赖项在发布的 pom 中不可见?此外,github 或类似网站上的完整工作示例将非常有帮助。
标签: java maven pom.xml maven-failsafe-plugin cucumber-serenity