IntelliJ IDEA 2016.1 Help

Creating Tests

In this section:

To create a test class using intention action

To create test cases for the supported testing frameworks, you can use the Create Test intention action. This intention action is available in the editor when the cursor is within the line containing the declaration of a class.

  1. Open the class of interest in the editor.
  2. Place the cursor within the line containing the class declaration.
  3. Press Alt+Enter to show the list of intention actions.
  4. Choose Create Test from the suggestion list.
    createTest1.png
  5. In the Create Test dialog:
    1. Select the testing library to be used.

      If the selected library is missing in your module, click the Fix button. As a result, the corresponding library will be automatically added to the module libraries.

    2. 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.
    3. Specify whether you want the setUp()/tearDown() methods (for JUnit), or the @Before/@After annotations to be generated.
    4. In the table that shows the list of all the methods of the source class, select the ones you want to generate test methods for.
    5. Click OK.
    createTest2.png

To create a test class using navigation

  1. Open the class of interest in the editor.
  2. Place the cursor within the line containing the class declaration.
  3. 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 are prompted to create it. Refer to the section Navigating Between Test and Test Subject for details.

See Also

Language and Framework-Specific Guidelines:

Last modified: 13 July 2016