Live Templates

JUnit 5 Test

@org.junit.jupiter.api.Test

@org.junit.jupiter.api.DisplayName("$NAME$")

void $METHOD$() throws Exception {

    $END$

}
intellij junit5 template
Figure 1. IntelliJ Live Template Editor

Edit Variables:

  • NAME

  • METHOD: default-value camelCase(NAME)

intellij junit5 variables
Figure 2. Editing template variables

SLF4J Logger Template

private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger( $CLASS$.class );

Edit variables:

  • CLASS: expression: className()

Favorite Shortcuts

Select whole block in Editor

Cmd+Tab+Down

Select similar blocks in editor

Ctrl+G

Copy the absolute Path of the current File into Clipboard

Cmd+Shift+C

Paste from history

Cmd+Shift+V

Hide all windows

to see only my precious editor

Cmd+Shift+F12

Bookmarks

Add bookmark

F3

View bookmarks

Cmd+F3

HTTP Request Tool

Using Variables in HTTP Request

We want to pass the current date as a timestamp into the JSON Parameters

### Alle Fahrten von Heute für die angegeben Verwaltung
< {%
    const today = new Date().toISOString().split('T')[0]
    request.variables.set("today", today)
%}
POST https://someservice/path/v1/thing
Content-Type: application/json
{
  "dateBetween": {
    "start": "{{today}}",
    "end": "{{today}}"
  },
  [..]
}

Existing dynamic Variables

$uuid or $random.uuid

generates a universally unique identifier (UUID-v4)

$timestamp

generates the current UNIX timestamp

$isoTimestamp

generates the current timestamp in ISO-8601 format for the UTC timezone.

$randomInt

generates a random integer between 0 and 1000.

$random.integer(from, to)

generates a random integer between from (inclusive) and to (exclusive), for example random.integer(100, 500). If you provide no parameters, it generates a random integer between 0 and 1000.

$random.float(from, to)

generates a random floating point number between from (inclusive) and to (exclusive), for example random.float(10.5, 20.3). If you provide no parameters, it generates a random float between 0 and 1000.

$random.alphabetic(length)

generates a sequence of uppercase and lowercase letters of length length (must be greater than 0).

$random.alphanumeric(length)

generates a sequence of uppercase and lowercase letters, digits, and underscores of length length (must be greater than 0).

$random.hexadecimal(length)

generates a random hexadecimal string of length length (must be greater than 0).

$random.email

generates a random email address.

$exampleServer

is replaced with the IntelliJ IDEA built-in web server, which can be accessed using HTTP Client only. The variable is used in GraphQL and WebSocket examples.

Resources