idea 使用junit5的坑。

idea 2016版本开始支持junit5,最好是2017.3。官方原文:
IntelliJ IDEA releases prior to IDEA 2017.3 bundle specific versions of JUnit 5. Thus, if you want to use a newer version of JUnit Jupiter, execution of tests within the IDE might fail due to version conflicts. In such cases, please follow the instructions below to use a newer version of JUnit 5 than the one bundled with IntelliJ IDEA.

2017.1.1版本解决办法。

org.junit.platform
junit-platform-launcher
1.0.0-M2
test


org.junit.jupiter
junit-jupiter-engine
5.0.0-M2
test


org.junit.vintage
junit-vintage-engine
4.12.0-M2
test

junit版本需要和idea版本对应。

参考链接:
https://www.jianshu.com/p/d04078355afc
https://junit.org/junit5/docs/current/user-guide/#running-tests-ide

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在IntelliJ IDEA使用JUnit进行测试的方法很简单。首先,确保你已经将JUnit库添加到你的项目中,这可以通过添加junit-4.12.jar和相关的hamcrest库(如hamcrest-core-1.3.rc2.jar和hamcrest-library-1.3.rc2.jar)来实现。 接下来,你可以通过多种方式在IntelliJ IDEA中创建测试文件。一种方式是使用快捷键,通过点击菜单栏中的Navigate选项,然后选择test创建测试文件。如果快捷键没有效果,你可以手动进行操作。 另一种方式是在要编写测试文件的类界面中使用快捷键Ctrl+Shift+T,然后点击Create New Test,在弹出的窗口中创建新的测试类。 最后,你还可以通过打开Project Structure菜单,选择Modules,然后点击Dependencies选项,将JUnit库添加到你的项目依赖中。你可以在加号上方点击鼠标,并选择第一项来添加依赖库。 这样,你就可以在IntelliJ IDEA使用JUnit进行测试了。你可以编写测试方法,并使用各种断言和注解来验证你的代码的正确性。希望这些信息对你有所帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [免费Idea使用junit测试需要的多个jar包](https://download.csdn.net/download/weixin_46071647/12398209)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [保姆级教程——IDEA使用Junit进行测试](https://blog.csdn.net/gmy012243/article/details/124653947)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值