idea使用Junit5出现TestEngine with ID ‘junit-jupiter‘ failed to discover tests报错

在Maven项目中使用JUnit调试时遇到错误,原因可能是不同版本的JUnit包冲突。解决方案是删除多余包,保留junit-jupiter-engine等必要依赖,并确保重新加载项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在由maven建立的项目中使用junit调试时,出现如下错误。并且import org.junit.Test时报错飘红

在网上查阅了一些文章后,发现可能的原因是 导入的jar包与原有的冲突。删除多余的包并重新加载项目后解决。(记得重新加载哦,就是idea右上角那个绿色的锤子图案)(不要问我为什么这样提醒你〒▽〒)

原本导入的包和保留的包如下:

<!--        <dependency>-->
<!--            <groupId>org.junit.jupiter</groupId>-->
<!--            <artifactId>junit-jupiter-api</artifactId>-->
<!--            <version>5.8.2</version>-->
<!--            <scope>test</scope>-->
<!--        </dependency>-->
<!--        <dependency>-->
<!--            <groupId>org.testng</groupId>-->
<!--            <artifactId>testng</artifactId>-->
<!--            <version>RELEASE</version>-->
<!--            <scope>test</scope>-->
<!--        </dependency>-->

<!--        <dependency>-->
<!--            <groupId>junit</groupId>-->
<!--            <artifactId>junit</artifactId>-->
<!--            <version>4.13.1</version>-->
<!--            <scope>test</scope>-->
<!--        </dependency>-->

        <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.9.3</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine -->
<!--        <dependency>-->
<!--            <groupId>org.junit.vintage</groupId>-->
<!--            <artifactId>junit-vintage-engine</artifactId>-->
<!--            <version>5.10.0</version>-->
<!--            <scope>test</scope>-->
<!--        </dependency>-->

        <!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher -->
<!--        <dependency>-->
<!--            <groupId>org.junit.platform</groupId>-->
<!--            <artifactId>junit-platform-launcher</artifactId>-->
<!--            <version>1.10.0</version>-->
<!--            <scope>test</scope>-->
<!--        </dependency>-->

解决办法参考了org.junit.platform.commons.JUnitException: Failed to parse version of junit:junit: 4.13.1_bmjhappy的博客-CSDN博客

还是小白,如果有任何不对的地方还请大家不吝赐教

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值