当我运行我的 Maven 构建时
clean verify -U -fae -P TestExecutor -DcucumberTag=@full -Dheadless=true
我收到以下错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project testing: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
这是我的pom.xml
<?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>com.xxx</groupId>
<artifactId>testing</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<cucumber.version>7.3.3</cucumber.version>
<selenium.version>4.1.4</selenium.version>
<awaitility.version>4.2.0</awaitility.version>
<assertj.version>3.22.0</assertj.version>
<commonsmodel.version>5.3.3</commonsmodel.version>
<maven.compiler.version>3.10.1</maven.compiler.version>
<maven.surefire.version>3.0.0-M5</maven.surefire.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<junit.jupiter.version>5.8.2</junit.jupiter.version>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/net.jodah/failsafe -->
<dependency>
<groupId>net.jodah</groupId>
<artifactId>failsafe</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${awaitility.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<configuration>
<skipTests>false</skipTests>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<includes>**/TestExecutor.java</includes>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>TestExecutor</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<configuration>
<skipTests>false</skipTests>
<testFailureIgnore>true</testFailureIgnore>
<test>
TestExecutor.java
</test>
<includes>
<includes>**/TestExecutor.java</includes>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
这是我的遗嘱执行人:
package com.xxx.tests;
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;
import static io.cucumber.junit.platform.engine.Constants.FEATURES_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.FILTER_TAGS_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("com/xxx")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.xxx")
@ConfigurationParameter(key = FILTER_TAGS_PROPERTY_NAME, value = "@full")
@ConfigurationParameter(key = FEATURES_PROPERTY_NAME, value = "web-testing/src/test/resources/features")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "json:target/cucumber.json, html:target/cucumber.html")
public class TestExecutor {
}
但无论如何,我在尝试使用 Maven 命令运行时都会遇到此错误,我需要它才能让我的测试在 Jenkins 上运行。
如果我在 IDE 中本地运行 TestExecutor 类,则每个标有 @full 的测试都会正常运行。
很难说出确切的问题是什么。你还没有制作出最小的复制器。看看如何提问。
但是这些是冲突的:
@ConfigurationParameter(key = FEATURES_PROPERTY_NAME, value = "web-testing/src/test/resources/features")
这告诉 Cucumber 在您的
features
包中查找功能。尽管它只能与 `mvn test -Dcucumber.features=....." 结合使用,以解决 Maven 对 JUnit 5 的有限支持。
@SelectClasspathResource("com/xxx")
这是告诉 Cucumber 在类路径上查找功能的方法。然而,前面的注释表明它们位于
features
包中,而不是 com.xxx
。