...
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 linkin the Unit Test Assistant view:
- Right-click a file in Project Explorer and select Unit Testing> Add test case(s) from the context menu:
Info title Spring Tests 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 the test type:
- Regular - Creates regular test cases.
- Parameterized - Creates parameterized test cases (see Creating a Parameterized Unit Test for details).
- Combined - Creates parameterized test cases for methods that can be tested against different arguments. For other methods, regular tests are created.
The options are only available if you configured UTA to use JUnit 4 (see Configuring General Options) because parameterization is not supported for JUnit 5 tests. - Specify the object initialization mode:
- Deep - (default) Prepares objects and mocks using data collected from the tested method and other methods that are called when the test is executed.
- Shallow - Prepares objects and mocks using data collected from the tested method. 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.
- (Optional) Enable or disable the Timeout for running created tests (in ms) option and specify the time limit (in milliseconds) for executing this set of test. If the time limit is exceeded, the test execution will stop and the test will fail. The information about the error will be displayed as a Recommendation in the UTA interface. This option is enabled and set to 1000 by default.
Select the methods for which you want to create test cases (you can use the Select All or Deselect All buttons for your convenience).
Info title Spring Tests 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.
- Click OK to create test cases.
UTA will add new test cases for all selected methods in the file (including methods that already have corresponding tests).
- View the tests to modify or uncomment the default UTA values if necessary.
- Run the test with UTA to collect coverage information and recommendations for possible improvements (see Executing Unit Tests with Unit Test Assistant).
...