无法在项目测试中执行目标org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test(default-test):未执行任何测试[已关闭]

amrnrhlw  于 2023-11-17  发布在  Maven
关注(0)|答案(2)|浏览(161)

**已关闭。**此问题需要debugging details。目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答问题。
8天前关闭。
Improve this question
当我运行我的maven build时,
第一个月
我得到以下错误
[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的测试都可以正常运行。

vjhs03f7

vjhs03f71#

另一个问题:

public class TestExecutor {

}

字符串
Surefire理解这个约定。但是,如果你在这个约定之外命名东西,你现在必须添加额外的配置。
这再次使你的问题变得更加复杂,然后它需要。
如果你可以用IDEA运行这个类,但不能用surefire,这表明你配置surefire的方式可能有问题。

7vux5j2d

7vux5j2d2#

这些是相互冲突的:

@ConfigurationParameter(key = FEATURES_PROPERTY_NAME, value = "web-testing/src/test/resources/features")

字符串
这会告诉Cucumber在features包中查找特性。尽管它只能与mvn test -D"cucumber.features=....."结合使用,以解决Maven对JUnit 5的有限支持。

@SelectClasspathResource("com/xxx")


这是告诉Cucumber在classpath上查找特性的方法。然而,前面的注解表明它们在features包中,而不是com.xxx
请注意,这仅适用于您的TestExecutor类实际上被Maven发现并执行的情况;“No tests were executed!”错误可能由于各种原因而发生。

相关问题