Creating Tests
On this page:
- Creating a test class using the Create Test intention action
- Creating a test class using navigation command
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.
- Open the class of interest in the editor.
- Place the cursor within the line containing the class declaration.
- Press Alt+Enter to show the list of intention actions.
-
Choose from the suggestion list.
-
In the Create Test dialog:
-
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.
-
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 the methods of the source class, select the ones you want to generate test methods for.
- Click OK.
-
Select the testing library to be used.
To create a test class using navigation
- Open the class of interest in the editor.
- Place the cursor within the line containing the class declaration.
- Do one of the following:
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
```
Procedures:
Reference:
Language and Framework-Specific Guidelines:
Last modified: 21 March 2017