java JUnit异常:ID为“junit-platform-suite”的测试引擎未能执行测试

mznpcxlj  于 2022-12-21  发布在  Java
关注(0)|答案(1)|浏览(130)

我有一个Junit 5套件类:

@Suite
@SelectClasses({
    AAATests.class,
    BBBTests.class
})
public class SanityTMTestsSuite5 {
}

我使用这个版本:

<junit-jupiter.version>5.9.1</junit-jupiter.version>

可靠配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M5</version>
    <configuration>
        <testFailureIgnore>false</testFailureIgnore>
        <includes>
            <include>**/SanityTMTestsSuite*.java</include>
        </includes>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${junit-jupiter.version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-suite</artifactId>
            <version>1.9.1</version>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>${junit-jupiter.version}</version>
        </dependency>
    </dependencies>
</plugin>

另一个依赖项在万无一失的定义之外:

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-suite</artifactId>
    <version>1.9.1</version>
    <scope>test</scope>
</dependency>

当我执行mvn test时,我得到
org.junit.platform.commons.JUnitException: ID为"junit-platform-suite"的测试引擎未能执行测试
原因:java. lang. NoSuchMethodError:'组织. junit.平台.启动程序.核心.启动程序发现结果组织. junit.平台.启动程序.核心.启动程序发现结果.带有保留引擎(java. util.函数. predicate )'

njthzxwz

njthzxwz1#

此配置对我很有效:

<?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>
        <junit.version>1.9.1</junit.version>
        <junit-jupiter.version>5.9.1</junit-jupiter.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <testFailureIgnore>false</testFailureIgnore>
                    <includes>
                        <include>**/SanityTMTestsSuite*.java</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>${junit-jupiter.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${junit-jupiter.version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite</artifactId>
            <version>${junit.version}</version>
        </dependency>
        <!--JUnit Jupiter Engine to depend on the JUnit4 engine and JUnit 4 API  -->
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>${junit-jupiter.version}</version>
        </dependency>
    </dependencies>
</project>

相关问题