intellij-idea Add a test method easily


Example

@org.junit.Test
public void should_$name$() {
    $END$
}

Make sure to check the Shorted FQ names box when creating this template.

configure live template

When you type "should" (the abbreviation), this will add the necessary import org.junit.Test; statement at the top of the file, and this code:

@Test
public void should_() {
    
}

It is thanks to the Shorten FQ names option that @org.junit.Test is reduced to simply @Test.

The $name$ variable is irrelevant, it could be named something else. The purpose of that variable is that when the template is inserted in the class, the cursor will be placed in the position of $name$, asking you to enter something.

After you entered a value for $name$ (effectively the name of the test method), the cursor will finally jump to $END$, a built-in variable, so that you can carry on and implement the test case.