With Unit Test Assistant you can easily create test suites by choosing the Create test suite option in the Unit Test Assistant view or in your IDE context menu. When you choose the Create test suite option, UTA will:
Run the created tests using the Track and make assertions functionality to add assertions (see Tracking Object Changes and Creating Assertions for details). If you are using Eclipse IDE, the Build Automatically option (Project menu> Build Automatically) must be enabled for assertions to be added. If the option is disabled, no assertions are added during the test run.
To customize test cases created by UTA, review the values and assertions in the test code and update them as necessary. In addition, you can re-run the tests with the Run option to enhance your tests cases using UTA recommendations (see Executing Unit Tests with Unit Test Assistant).
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. |
You can specify the time limit for executing a test suite by configuring the Configure tests with timeout (in ms) option in the UTA Preferences (see Test creation options). |
Open the Unit Test Assistant - Create test suite dialog in one of the following ways:
Select a class in the editor and click the Create test suite action link in the Unit Test Assistant view:
Right-click a file in Project Explorer and select Unit Testing> Create test suite from the context menu:
Configure the test creation options.
Optimize test suite for: - Allows you to specify your priorities for creating tests for the selected methods.
- Maximum code coverage - UTA will create as many tests as is required to cover the maximum possible number of method execution paths. Enabling this option will help you achieve the highest coverage rate, but the complexity and potential overlap of test cases may impact their maintenance.
- Test suite maintainability - UTA will create fewer tests only to cover the main execution paths. Enabling this option will help you create less complex and better maintainable tests, but the coverage rate will be lower.
Mock initialization - Allows you to 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.
Create test cases for: - Allows you to specify the methods for which you want to create test cases. You can use Select All, Deselect All, or Select Modified (*) buttons to update the selection in the list. The Select Modified (*) button selects only the methods which have been modified in source control (indicated by an asterisk).
Note:
Due to limitations in Intellij before 2020.3, newly created files which have not been added to source control may not be included when detecting the modified source files and methods.
Eclipse and IntelliJ must recognize the project as a Git project in order for the modified methods functionality to work properly.
UTA can create test cases in bulk – for more than one file at once.
You can decide to only add test cases that increase coverage by selecting this option in the UTA Preferences (see Test creation options). |
Click Unit Testing> Create test suite to open the the Unit Test Assistant -Create test suite dialog.
Mock initialization - Allows you to 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.
Note:
The number in parentheses is an estimate of the number of files for which tests will be created. The actual number might be different as the test creation process performs a more detailed analysis of your code and optimization of test cases.
Due to limitations in Intellij before 2020.3, newly created files which have not been added to source control may not be included when detecting the modified source files and methods.
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.
|