IntelliJ IDEA 2023.1 Help

Creating Tests

IntelliJ IDEA suggests a way to create tests for classes and individual methods.

Create a test for a class or method

  1. In the editor, place the caret at the class declaration, or somewhere within a method.

  2. Do one of the following:

    • From the main menu, choose Navigate | Test.

    • From the context menu, choose Go To | Test.

    • Press Ctrl+Shift+T.

    IntelliJ IDEA shows the list of available tests.

  3. If the desired test doesn't yet exist, click Create new test.

    The Create Test dialog opens.

  4. In the Create Test dialog, specify the following settings:

    • Target directory, where the new test class will be generated.

    • The name of the test file, and the name of the test class.

    • Select the checkboxes next to the methods you want to include in the test class.

      Note that if the caret has been placed within a method, only this method name is included in the list.

  5. Click OK when ready. IntelliJ IDEA generates the test file in the specified location.

Once the test is created you can run it. See Run tests for more details.

Last modified: 21 September 2022