[英]JUnit 5 + Cucumber parallel test execution doesn't work with filesafe (Maven)
Good day.再会。 I can't execute my test in parallel threads.
我无法在并行线程中执行我的测试。 My Runner:
我的跑步者:
package parallel;
import io.cucumber.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
public class RunCucumberIT {
}
My POM file我的 POM 文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<groupId>org.example</groupId>
<artifactId>petstore</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.10.2</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>6.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<executions>
<execution>
<goals>
<goal>verify</goal>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
<parallel>classesAndMethods</parallel>
<threadCount>2</threadCount>
<perCoreThreadCount>true</perCoreThreadCount>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I'm use mvn failsafe:integration-test
command to start tests.我正在使用
mvn failsafe:integration-test
命令开始测试。 But all tests run in the same thread.但是所有测试都在同一个线程中运行。
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< org.example:petstore >------------------------
[INFO] Building petstore 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-failsafe-plugin:3.0.0-M5:integration-test (default-cli) @ petstore ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running parallel.RunCucumberIT
Thread ID - 1 - Scenario Outline Row 1 from scenario-outlines feature file.
Thread ID - 1 - Scenario Outline Row 2 from scenario-outlines feature file.
Thread ID - 1 - Scenario 1 from scenarios feature file.
Thread ID - 1 - Scenario 2 from scenarios feature file.
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.198 s - in parallel.RunCucumberIT
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.419 s
[INFO] Finished at: 2021-03-17T19:32:29+03:00
[INFO] ------------------------------------------------------------------------
Process finished with exit code 0
This is my steps definitions:这是我的步骤定义:
package parallel;
import io.cucumber.java.en.Given;
public class StepDefs {
@Given("Step from {string} in {string} feature file")
public void step(String scenario, String file) {
System.out.format("Thread ID - %2d - %s from %s feature file.\n",
Thread.currentThread().getId(), scenario,file);
}
}
This is my feature files The first:这是我的功能文件第一个:
Feature: Scenarios feature file
Scenario: Scenario Number One
Given Step from 'Scenario 1' in 'scenarios' feature file
Scenario: Scenario Number Two
Given Step from 'Scenario 2' in 'scenarios' feature file
And the second:第二个:
Feature: Scenario Outlines feature file
Scenario Outline: <scen_out_row_num>
Given Step from '<scen_out_row_num>' in 'scenario-outlines' feature file
Examples:
| scen_out_row_num |
| Scenario Outline Row 1 |
| Scenario Outline Row 2 |
I tried to use "mvn clean verify" command, but it runs all test runners even those doesn't meet "**/*IT.java" pattern (And he does it consistently) I couldn't find any working solutions for this problem.我尝试使用“mvn clean verify”命令,但它运行所有测试运行程序,即使那些不符合“**/*IT.java”模式的运行程序(而且他一直这样做)我找不到任何可行的解决方案问题。 Thanks in advance
提前致谢
Please note that mixing junit 5
, cucumber-junit-platform-engine
and maven-failsafe-plugin
requires maven-failsafe-plugin 2.22.2
, otherwise tests will be run but won't be captured, resulting in [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
.请注意,混合
junit 5
, cucumber-junit-platform-engine
和maven-failsafe-plugin
需要maven-failsafe-plugin 2.22.2
,否则将运行测试但不会被捕获,导致[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
。 This is both true for single threaded and parallel execution.这对于单线程和并行执行都是如此。
It seems maven-failsafe-plugin v3.0.0-Mx
has some kind of problem capturing the tests run. maven-failsafe-plugin v3.0.0-Mx
似乎在捕获测试运行时存在某种问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.