IntelliJ: customizing generated test method naming

If I generate a test for a class that assumed a method getId()

, the corresponding test method would be called getId()

.

Is it possible to set IntelliJ to add some static prefix for auto generated test methods?

For example:

getId()

shouldGetId()

doStuff()

shouldDoStuff()

+3


source to share


2 answers


Go to Preferences > Editor > File and Code Templates

and select JUnit4 Test Method

. This by default has the form

@org.junit.Test
public void test${NAME}() {
  ${BODY}
}

      

Change to



@org.junit.Test
public void should${NAME}() {
  ${BODY}
}

      

File and code templates

+5


source


You can easily change the test method template like this:

Step 1:

Create a test class and press ALTR + Insert on your keyboard and you will see a popup as shown in the following screenshot. Then press the right arrow key on your keyboard and the Edit Template menu opens. Then click on it.

enter image description here

Step 2:



Change the method template as needed and click ( For my reason it will be redirected to TestNG method template, but yours will be JUnit ).

enter image description here

Step 3:

When you insert the method with ALTR + Insert (shown in the first step) click on the Test Method menu, then it will generate the method like this: enter image description here

+3


source







All Articles