Issue
The menu item Code
> Generate…
> Test…
displays this dialog box.
alt="enter image description here">
…and produces a method like this in the resulting test class:
@Test
void fromDuration () {
}
I want the @DisplayName
annotation (new in JUnit 5) to be automatically inserted as well, for each test method being generated. Like this:
@Test
@DisplayName( "NameGoesHere" )
void fromDuration () {
}
➥ Is there a way to change the way IntelliJ generates the test to include the @DisplayName
annotation?
I looked for some template to edit, but could not find one.
Solution
JUnit 5 method template can be configured in Settings
(Preferences
on Mac) | Editor
| File and Code Templates
| Code
tab, JUnit 5 Test Method:
Change this:
@org.junit.jupiter.api.Test
void ${NAME}() {
${BODY}
}
…to this:
@org.junit.jupiter.api.Test
@org.junit.jupiter.api.DisplayName ( "NameGoesHere" )
void ${NAME}() {
${BODY}
}
Answered By - CrazyCoder
Answer Checked By - Mary Flores (JavaFixing Volunteer)