With Unit Test Assistant you can easily create multiple test cases for methods from a selected class, as well items selected in the Project Explorer. The methods are analyzed to create runnable test cases with initial values and sample assertions, which can be easily modified or uncommented. You can add test cases using the UTA interface or the Eclipse context menu.
- If the Unit Test Assistant view is not already open, choose Parasoft> Show View> Unit Test Assistant from the Eclipse menu bar.
- Select a class in the editor.
- Click the Add test case(s) button in the UTA interface.
Alternatively, you can right-click a class in the editor and select Unit Testing> Add test case(s) from the context menu.
The Unit Test Assistant - Add test case(s) dialog will open. - 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. - 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. - (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 you want to create test cases for.
- Click OK.
- 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).
Alternatively, you can add test cases using the Eclipse context menu in the Package Explorer.
- Right-click an item in the Project Explorer.
- Click Unit Testing> Add test case(s) to open the Unit Test Assistant dialog and follow the steps 4-8 described above.
If you select one file:
- You can specify the test type (regular, parameterized, or combined) and select the methods you want to create test cases for.
- UTA will add new test cases for all selected methods in the file.
If you select a scope larger than one file:
- You can specify the test type (regular, parameterized, or combined), but you cannot specify individual methods.
- UTA will skip the files that are not testable or whose corresponding test classes already exist.
You can create test cases for individual methods selected in the Package Explorer if they are of the same class. If you select methods from different classes, or an individual method and a class or a package, test cases will not be generated.