Redefine template used to create a JUnit 5 class via "Create test" feature of IntelliJ 2019

Basil Bourque

The menu item Code > Generate… > Test… displays this dialog box.

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.

CrazyCoder

JUnit 5 method template can be configured in Settings (Preferences on Mac) | Editor | File and Code Templates | Code tab, JUnit 5 Test Method:

method template

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}
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Create Test Class in IntelliJ

Intellij Create Test missing JUnit

Create test instance in Junit 5 with factory method (no dynamic test)

How to redefine the template class constructor via a macro in C++11?

Junit/Java create test method for void with exception

How to create a test directory in Intellij 13?

using eclipse template to create test cases

How do I Dynamically create a Test Suite in JUnit 4?

How to create a Test Suite in Eclipse under org.junit

How to create test suite for Mockito when we are writing junit

Is there an equivalent of Junit5 TestTemplateInvocationContextProvider that can be used on class level?

IntelliJ ignores JUnit 5

IntelliJ + JUnit 5 (Jupiter)

how to create test class and folder from android studio?

Using a constant class to create test descriptions for Testng test description

Is it possible to change default class name template for junit4 test in Intellij Idea?

Junit5 with IntelliJ and Gradle

How to Mock a Service Class in Spring Boot to be used in the testing of another Service Class? JUNIT 5

Create test data in BigQuery

Rust Create Test Setup

create test for activatedRoute data

Create a Class to be used on controllers

Can the "Windows Desktop Class Library" template be used to create a class library used by mutliple ASP.NET web applications?

How can I create a test object of a specific GUI class with the class determined at test runtime?

Automatic memory pool feature by template class

IntelliJ cannot run JUnit test class

IntelliJ Junit5 Tests are not discoverable

Gradle project running jUnit 5 tests in IntelliJ

Including JUnit 5 dependency in IntelliJ IDEA