With Unit Test Assistant you can easily create multiple test cases for methods from a selected class or items selected in the Project Explorer by choosing the Add test case(s) option in the Unit Test Assistant view or in your IDE context menu. The methods are analyzed to create runnable test cases with initial values and sample assertions, which can be easily modified or uncommented.
UTA requires 2 GB of RAM for bulk creation. If you create multiple test cases for a large code base, we recommend configuring your IDE to use 4 GB of RAM. |
We recommend that you disable the Synchronize files on frame or editor tab activation option in the IntelliJ settings. If enabled, UTA may occasionally abort and then resume the test creation process, which may result in failing to generate one test, or generating a test that is incomplete. To disable the option:
|
UTA creates test for private methods in the selected classes if the Create tests for private methods option in the UTA Preferences is enabled (see Configuring Preferences). By default, the Create tests for private methods option is disabled, since the industry best practice is to test private methods by creating tests for the accessible methods that call them, rather than by creating tests for private methods directly. |
Open the Unit Test Assistant - Add test case(s) dialog in one of the following ways:
- Select a class in the editor and click the Add test case(s) action link in the Unit Test Assistant view:
- Right-click a file in Project Explorer and select Unit Testing> Add test case(s) from the context menu:
If you are creating multiple tests for Spring components, the button label will change into Add Spring test case(s). See Creating a Spring Unit Test for more information about creating and configuring Spring unit tests with UTA. |
Specify how you want mocks to be initialized:
- Configure within test method - Initializes mocks by declaring and initializing the object under test and its dependencies within the test method.
- Use @InjectMocks - Initializes mocks by using the @InjectMocks annotation to mark fields on which mock injection should be performed and the @Mock annotation for dependencies.
See Configuring Mock Initialization for details.
Select the methods for which you want to create test cases (you can use the Select All or Deselect All buttons for your convenience).
If UTA detects Spring classes in the selected resources, it will display additional options: - Use Spring test framework within tests for Spring classes -allows you to specify the kind of tests you want to create for Spring classes: if enabled, UTA will create the tests using the Spring test framework (see Spring MVC Test Framework for details); if disabled, UTA will create standard JUnit tests. - Select Spring Handler Methods - allows you to select all the Spring controller handler methods and deselect all the other methods in the list. See Creating a Spring Unit Test for details about support for the Spring framework. |
You can create test cases for more than one file.
Click Unit Testing> Add test case(s) to open the the Unit Test Assistant - Add test case(s) dialog.
Creating test cases for more than one file requires the 'Bulk creation' license feature. The feature provides license tokens that monitor the number of files for which test cases are generated (the number of tokens depends on your license agreement). When creating test cases for multiple files, UTA consumes one token per .java file you selected.
|
To streamline test creation, we recommend that you leverage UTA's capability to automatically update multiple test with available assertions.
See Tracking Object Changes and Creating Assertions for details.