设置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>
相关推荐
酷爱码1 小时前
IDEA 中 Maven Dependencies 出现红色波浪线的原因及解决方法
java·maven·intellij-idea
有梦想的攻城狮1 天前
maven中的maven-antrun-plugin插件详解
java·maven·插件·antrun
RainbowJie12 天前
从零到一:Maven 快速入门教程
java·maven
RainbowJie12 天前
Maven的生命周期
java·maven
凌辰揽月2 天前
Web后端基础(Maven基础)
前端·pycharm·maven
程序员葵安2 天前
【Java Web】9.Maven高级
java·数据库·后端·maven
eternal__day2 天前
微服务架构下的服务注册与发现:Eureka 深度解析
java·spring cloud·微服务·eureka·架构·maven
青衫红叶3 天前
Idea使用springAI搭建MCP项目
java·spring cloud·maven·intellij-idea·spring-ai
杨DaB4 天前
【JavaWeb】Maven、Servlet、cookie/session
hive·servlet·maven
Aric_Jones4 天前
HashMap 的底层原理
java·eclipse·maven·hashmap·hash