设置provider解决maven找不到JUnit 5测试样例

问题描述

尝试复现一个用大模型生成测试样例的工作,但使用maven生成的JUnit 5测试样例死活不执行。又不想用命令行运行,因此进行排查

基本知识

<dependencies>

junit-jupiter-api JUnit 5写代码时调用的库
junit-jupyter-engine 运行JUnit 5测试样例的引擎(TestEngine)

<plugins>

maven-surefire-plugin 执行 mvn test时实际执行的插件。它需要一个Provider来提供测试样例,需要一个TestEngine的实现来执行测试样例

问题细节与分析

已经正确设置了<dependencies>,也确认了测试样例的类被正确编译,但就是不执行

分析maven执行轨迹,发现一条:

复制代码
[INFO] --- surefire:3.3.1:test (default-test) @ tullibee-api ---
[INFO] Using auto detected provider org.apache.maven.surefire.junit4.JUnit4Provider

原来是Provider出错。不知道为什么,maven-surefire-plugin自动选择Provider出错了

解决方法

手动设置Providersurefire-junit-platform。以下为样例:

复制代码
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.3.1</version>
            <configuration>
                    <includes>
                            <include>EClientSocket_reqContractDetails_*.java</include>
                    </includes>
            </configuration>
            <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit-platform</artifactId>
                        <version>3.3.1</version>
                    </dependency>
            </dependencies>
        </plugin>
相关推荐
永不停歇的蜗牛3 小时前
Maven的POM文件相关标签作用
服务器·前端·maven
洛克大航海9 小时前
Maven 的下载安装配置教程
java·maven
zhengfei61111 小时前
CVE-2025-49844 深度分析
junit
Mr.朱鹏11 小时前
RocketMQ可视化监控与管理
java·spring boot·spring·spring cloud·maven·intellij-idea·rocketmq
醇氧12 小时前
JUnit 5的 Assertions
junit
咖啡不甜不好喝13 小时前
IDEA Maven设置所有项目生效
maven·idea
0和1的舞者13 小时前
《Maven 核心功能与仓库体系详解》
ide·maven·项目管理·仓库·依赖
杀死那个蝈坦14 小时前
OpenResty
junit·openresty
q***062915 小时前
(CICD)自动化构建打包、部署(Jenkins + maven+ gitlab+tomcat)
自动化·jenkins·maven
Mr.朱鹏1 天前
RocketMQ安装与部署指南
java·数据库·spring·oracle·maven·rocketmq·seata