设置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>
相关推荐
小江的记录本11 小时前
【Java基础】Java 8-21新特性:JDK21 LTS:虚拟线程、模式匹配switch、结构化并发、序列集合(附《思维导图》+《面试高频考点清单》)
java·数据库·python·mysql·spring·面试·maven
二宝哥11 小时前
离线安装maven
java·数据库·maven
小江的记录本12 小时前
【Java基础】反射与注解:核心原理、自定义注解、注解解析方式(附《思维导图》+《面试高频考点清单》)
java·数据结构·python·mysql·spring·面试·maven
小兔崽子去哪了16 小时前
将自己项目发布到 maven 仓库
maven
wh_xia_jun19 小时前
给小白的 Maven 命令行执行测试 完整指南
git·maven·intellij-idea
happymaker062620 小时前
SpringBoot学习日记——DAY04(整合junit,myBatis)
spring boot·学习·junit
一条泥憨鱼20 小时前
详解MySQL事务(超详细版)
java·数据库·mysql·spring·maven·后端开发
wh_xia_jun2 天前
How to Write Test Cases in Java Application using Mockito and Junit?
junit
Tirzano2 天前
批量查询在线成员对应节点redis
数据库·redis·junit
小江的记录本2 天前
【Java基础】集合框架: ArrayList vs LinkedList 核心区别、扩容机制(附《思维导图》+《面试高频考点清单》)
java·数据库·python·mysql·spring·面试·maven