通过IntelliJ 2019的“创建测试”功能重新定义用于创建JUnit 5类的模板

问题描述 投票:1回答:1

菜单项Code> Generate…> Test…显示此对话框。

enter image description here

...并在生成的测试类中生成这样的方法:

@Test
void fromDuration () {
}

对于生成的每个测试方法,我希望自动插入@DisplayName注释(JUnit 5中的新增内容)。像这样:

@Test
@DisplayName( "NameGoesHere" )
void fromDuration () {
}

➥有没有办法改变IntelliJ生成测试的方式以包含@DisplayName注释?

我找了一些要编辑的模板,但找不到。

templates intellij-idea junit junit5 junit-jupiter
1个回答
1
投票

可以在Settings(Mac上的Preferences)中配置JUnit 5方法模板Editor | File and Code Templates | Code选项卡,JUnit 5测试方法:

method template

改变这个:

@org.junit.jupiter.api.Test
void ${NAME}() {
  ${BODY}
}

......对此:

@org.junit.jupiter.api.Test
@org.junit.jupiter.api.DisplayName ( "NameGoesHere" )
void ${NAME}() {
  ${BODY}
}
© www.soinside.com 2019 - 2024. All rights reserved.