相关疑难解决方法(0)

org.junit.platform.commons.JUnitException:ID为“junit-jupiter”的TestEngine未能发现测试

我想在 Gradle 项目中实施 Junit 5 测试。我试过这个:

梯度配置:

plugins {
    id 'org.springframework.boot' version '2.5.5'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'test'
version = '0.0.1'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

ext {
    set('springCloudVersion', "2020.0.4")
}

dependencies {
    ...............
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

test {
    useJUnitPlatform()
}
Run Code Online (Sandbox Code Playgroud)

联合测试:

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import java.util.concurrent.TimeUnit;

public class GeneratePdf {

    @DisplayName("Test MessageService.get()")
    @Test
    @Timeout(value = 60, unit …
Run Code Online (Sandbox Code Playgroud)

java junit spring-test junit5 junit-jupiter

57
推荐指数
4
解决办法
13万
查看次数

ID 为“junit-jupiter”的 TestEngine 未能发现测试 - 原因:org.junit.platform.commons.JUnitException:ClassSelector 解析失败

我在运行集成测试时遇到问题。

作为测试的一部分,我习惯于exec-maven-plugin从源代码管理中提取其他项目,然后在本地运行它们,以便我的测试可以使用它来执行。

我的 JUnit Maven 依赖项是:

<plugins>
    <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>3.0.0-M5</version>
        <configuration>
            <useModulePath>false</useModulePath>
            <useSystemClassLoader>false</useSystemClassLoader>
            <skipTests>false</skipTests>
            <includes>
                <include>**/*IntegrationTest.java</include>
            </includes>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>
...
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <version>2.4.2</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
    </exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我创建了一个名为的配置文件,integration-test以便我可以选择何时启用集成测试,并且还添加了一个参数来maven-surefire-plugin调用,skipUTs以便我可以跳过单元测试。

运行输出: mvn clean verify -Pintegration-test -DskipUTs=true

org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
    at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:111)
    at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:85)
    at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:92)
    at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:67)
    at org.apache.maven.surefire.junitplatform.TestPlanScannerFilter.accept(TestPlanScannerFilter.java:56)
    at org.apache.maven.surefire.api.util.DefaultScanResult.applyFilter(DefaultScanResult.java:102)
    at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.scanClasspath(JUnitPlatformProvider.java:147)
    at …
Run Code Online (Sandbox Code Playgroud)

java junit maven junit5

6
推荐指数
1
解决办法
1548
查看次数

标签 统计

java ×2

junit ×2

junit5 ×2

junit-jupiter ×1

maven ×1

spring-test ×1