IntelliJ IDEA 2019.2 Help

Creating Tests

You can create test classes for the supported testing frameworks using the intention action.

  1. Open the necessary class in the editor and place the cursor on a class name.

  2. Press Alt+Enter to invoke the list of available intention actions.

  3. Select Create Test.


    Alternatively, you can place the cursor on the class name and select Navigate | Test from the main menu, or select Go to | Test from the shortcut menu, and click Create New Test.

  4. In the Create Test dialog, configure the required settings. You can specify a testing library you want to use, configure a test class name and its location, and select methods for which you want to generate test classes.

Create test methods

To create stub test methods in JUnit test classes, you can use the IntelliJ IDEA code generation feature.

  1. Open the corresponding JUnit test class in the editor.

  2. Place the cursor where you want a new test method to be generated.

  3. Press Alt+Insert and select Test Method from the Generate menu.

Configure naming pattern for generated test classes

By default, IntelliJ IDEA attaches the Test suffix to source class names when it automatically generates test classes. You can change the naming pattern for test classes.

  1. In Settings/Preferences (Ctrl+Alt+S, go to Editor | Code Style | Java, and open the Code Generation tab.

  2. In the Naming section of the tab, type a suffix or a prefix (or both) that you want to use for naming generated test classes into the corresponding fields.

Last modified: 17 October 2019