菜单项Code
> Generate…
> Test…
显示此对话框。
...并在生成的测试类中生成如下方法:
@Test
void fromDuration () {
}
我想要@DisplayName
对于生成的每个测试方法,也会自动插入注释(JUnit 5 中的新功能)。像这样:
@Test
@DisplayName( "NameGoesHere" )
void fromDuration () {
}
➥ 有没有办法改变 IntelliJ 生成测试的方式以包含 @DisplayName
注释?
我寻找一些要编辑的模板,但找不到。
最佳答案
JUnit 5 方法模板可以在设置
(Mac 上的首选项
)中配置 | 编辑器
| 文件和代码模板
| 代码
选项卡,JUnit 5测试方法:
更改此:
@org.junit.jupiter.api.Test
void ${NAME}() {
${BODY}
}
…对此:
@org.junit.jupiter.api.Test
@org.junit.jupiter.api.DisplayName ( "NameGoesHere" )
void ${NAME}() {
${BODY}
}
关于templates - 通过 IntelliJ 2019 的 "Create test"功能重新定义用于创建 JUnit 5 类的模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54817068/