查了查,网上主流解决办法两种。1点击file-settings.-Build,Execution,DeploymentBuildToolsMavenRunner,勾选delegateID...
查了查,网上主流解决办法两种。
1 点击file-> settings. ->Build, Execution, Deployment–>Build Tools–>Maven–>Runner,勾选delegate IDEA build/run actions to maven(将idea的运行权限委托给maven)
![解决Idea运行junit测试时报Error:[3,17] 程序包org.junit不存在的问题](https://www.easck.com/d/file/p/2023/03-09/71a3f039d79af94e3c8322c2c105f76f.jpg)
该方法能解决问题(至少我行),但不推荐。每次测试都要将整个maven项目运行出来,效率极低。
2.将maven 仓库换成idea 默认仓库,即c盘用户下.m2文件夹下的本地仓库。这种办法某种意义上也不推荐。另设置本地仓库的目的就是防止占用C盘空间,防止系统运行越来越慢。此种解决方式违背我们初衷。
我的办法。
在之前,先确认五件事
1 .确保mavensetting文件中的本地仓库配置正常
![解决Idea运行junit测试时报Error:[3,17] 程序包org.junit不存在的问题](https://www.easck.com/d/file/p/2023/03-09/4f286f4de6b6f9c83d631c98e169d1a7.jpg)
2.确保IDEA中maven的配置正常
![解决Idea运行junit测试时报Error:[3,17] 程序包org.junit不存在的问题](https://www.easck.com/d/file/p/2023/03-09/16b473208946344392c0c7907008f88d.jpg)
3 确认 jar包坐标和当前依赖管理使用的jar包版本一致
![解决Idea运行junit测试时报Error:[3,17] 程序包org.junit不存在的问题](https://www.easck.com/d/file/p/2023/03-09/7e8aac6ac16baaaf7c0151398c48ea21.jpg)
4 确认与idea绑定配置的本地maven仓库有完整的目标jar包。
![解决Idea运行junit测试时报Error:[3,17] 程序包org.junit不存在的问题](https://www.easck.com/d/file/p/2023/03-09/0ab8bc93b4c70740d894e6fec04e173d.jpg)
5.(1)确认seting 配置里Java compiler Project bytecode version 为1.8 或者8;
(2)Target bytecode version 版本号与你pom文件下
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>???</maven.compiler.source>
<maven.compiler.target>???</maven.compiler.target>
</properties>
配置的版本号一致.若你没有在pom文件配置该标签体内容,Target bytecode version默认为1.5。以我为例
![解决Idea运行junit测试时报Error:[3,17] 程序包org.junit不存在的问题](https://www.easck.com/d/file/p/2023/03-09/13965848d686e24938d0bcdce676a214.jpg)
![解决Idea运行junit测试时报Error:[3,17] 程序包org.junit不存在的问题](https://www.easck.com/d/file/p/2023/03-09/1268273d5c076b0a89fe40ccd06143dd.jpg)
![解决Idea运行junit测试时报Error:[3,17] 程序包org.junit不存在的问题](https://www.easck.com/d/file/p/2023/03-09/e52ebda0e3b6dc3bbbef59553c3bb48b.jpg)
因为我maven_java_1没有配置<properties></properties>,所以setting中 Target bytecode version默认为1.5
将以上五件事确认无误做出正确修改,重启计算机后,若还是不行,再做以下操作(我个人如此)
1 则先将idea maven本地仓库绑定至默认maven仓库.c盘下——>user ->.m2文件夹下的默认仓库(注意要一并修改maven 中 的setting.XML文件,将其local repository 标签体注释即可);修改idea下的maven配置至默认仓库地址(不重复赘述,之前的图有)该刷新maven仓库刷新,再重新运行。此刻应该能正常运行。
2 再重新将默认本地php仓库修改回自己目标本地仓库,修改maven 中 的setting.xml文件,修改idea
maven 配置(照着前图修改,不重复赘述)
愿能帮你。
到此这篇关于解决Idea运行junit测试时报Error:[3,17] 程序包org.junit不存在的问题的文章就介绍到这了,更多相关程序包org.junit不存在内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!










