bcl*_*man 7 java junit intellij-idea junit5 junit-jupiter
我已经在 IntelliJ IDEA 中设置了 JUnit,并进行了一系列测试,但其中没有任何内容。当我运行它们时,它们都按预期通过。但是,当我输入“assertEquals”时,它显示为红色。当我将鼠标悬停在它上面时,它显示“无法解析方法”。
我用谷歌搜索了一下,看起来我需要这样做:
import static org.junit.Assert.*;
Run Code Online (Sandbox Code Playgroud)
但是,当我开始输入 时import static org.junit.,下一个选项是“*”、“jupiter”或“platform”...
作为参考,我的 IDE 中的示例测试如下所示:
@org.junit.jupiter.api.Test
void isButton() {
assertEquals()
}
Run Code Online (Sandbox Code Playgroud)
知道如何解决这个问题吗?
谢谢!
类的完整路径Assertions是:
org.junit.jupiter.api.Assertions.assertEquals
Run Code Online (Sandbox Code Playgroud)
确保您已将Jupiter API添加到依赖项中:
摇篮:
dependencies {
testCompile("org.junit.jupiter:junit-jupiter-api:5.9.0")
}
Run Code Online (Sandbox Code Playgroud)
行家:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
有一个关于 IntelliJ IDEA 和 JUnit 5 的很好的指南。请看一下:Using JUnit 5 in IntelliJ IDEA
| 归档时间: |
|
| 查看次数: |
7337 次 |
| 最近记录: |