IntelliJ IDEA 2017.2 Help

Creating Tests

On this page:

To create a test class using the intention action

To create test cases for the supported testing frameworks, you can use the Create Test intention action.

  1. Open the class you want to create a test for in the editor, and place the cursor on the class name.
  2. Press Alt+Enter to invoke the list of available intention actions.
  3. Choose Create Test from the list.
    createTest1.png
  4. In the Create Test dialog:
    • Select the testing library to be used.

      If the selected library is missing from your module, click the Fix button. The corresponding library will be automatically added to the module libraries.

    • Define the name and location of the test class to be generated.
      • In the Class name field, specify the name of the stub test class to be generated.
      • In the Superclass field, IntelliJ IDEA suggests the appropriate super class for JUnit3. For JUnit 4 and TestNG, this field is blank.
      • In the Destination package field, define where the generated test class should be placed.
    • Specify whether you want the setUp()/tearDown() methods (for JUnit), or the @Before/@After annotations to be generated.
    • In the table that shows the list of all methods of the source class, select the ones you want to generate test methods for.
      createTest2.png

To create a test class using navigation

  1. Open the class you want to create a test for in the editor, and place the cursor on the class name.
  2. Do one of the following:
    • On the main menu, choose Navigate | Test.
    • On the context menu, choose Go to | Test.

If the target test doesn't exist, you will be prompted to create it. Refer to Navigating Between Test and Test Subject for details.

Last modified: 29 November 2017

See Also

Procedures:

Language and Framework-Specific Guidelines: