设置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>
相关推荐
暮雨哀尘17 小时前
JAVA基础练习(四):SpringBoot 实现简易登录功能
java·spring boot·eclipse·maven
hanchenxing1 天前
CI/CD流水线中的构建缓存:从原理到最小可运行示例CI/CD
maven·构建缓存
愛芳芳2 天前
Swagger2 多环境动态配置实战指南
java·后端·maven·springboot·swagger
金玉满堂@bj3 天前
多环境部署方案(开发、测试、生产,搭配Tomcat\+WAR包)
java·tomcat·maven
青春易逝丶3 天前
Maven
java·maven
写后端的胖头鱼5 天前
一文学会单元测试之----Junit
junit·单元测试
howard20055 天前
3.3 开发环境 - Maven
maven·安装·配置·阿里镜像源
xinjia_ctrl6 天前
暑假实习总结
git·后端·spring·maven·intellij-idea
网络豆6 天前
Apache Maven 鸿蒙 PC 适配全记录:把 JVM 构建工具交付到 HiShell
maven·apache·harmonyos