Introduction
Unit Test Assistant can identify gaps in test coverage and provide guidance for covering these gaps. You can increase code coverage using Uncovered code recommendations in the the Recommendations tab or the Cover the line option in the Unit Test Assistant view.
Uncovered code recommendations are displayed after your tests are run and include action links and suggestions to guide you through the process of covering the uncovered source code.
The Cover the line option allows you to create from scratch a test case to cover the uncovered line you selected in the editor.
Increasing Coverage with UTA Recommendations
The 'Uncovered code' recommendation must be enabled in UTA preferences (see Configuring Preferences).
When you run your test, UTA will display Uncovered code recommendations in the Recommendations view. Recommendations for the largest uncovered code fragments are displayed first – UTA will guide you through progressively smaller chunks of uncovered code as you address coverage gaps.
To increase coverage, you can either modify or extend existing test cases or clone and modify an existing test case with UTA.
Modifying a Test Case
The Recommendations panel may display hints that describe how the test case should be modified to cover the code. By analyzing the flow of the program, it can provide information about parameter values that satisfy the conditions of flow control statements.
Cloning and Updating a Test Case
The Clone test action displays a list of existing tests that you can copy and modify to quickly increase coverage.
- Click Clone test. UTA will analyze the available tests and recommend the most suitable test to clone.
- Select the test you want to clone. Depending on the test code, the following clone types may be available:
- clone only – UTA makes a copy of the test without changing the test code. You need to manually modify the cloned test.
- clone with suggested value(s) – UTA makes a copy of the test and automatically updates the cloned test – according to the hints. For example:
Hints:
The automatically updated test:
- Click OK.
Covering a Selected Line
The Unit Test Assistant view displays the Cover the line option when you select a testable code line in your editor. The option allows you to create a new test case to cover the line you selected. By analyzing your source code, UTA can identify the values that are required for the test case to cover the selected line.
- Select the code line you want to cover.
- Click the Cover the line option to create a new test case.
UTA will create a new test case and automatically configure the values that are required for the test to cover the line. - Run the test to verify that the selected line is covered.
For some code lines, UTA may calculate the values required to cover the line but it may be unable to automatically configure one or more of these values during test generation. As a result, the created test case will include a comment that lists all the required values, regardless of whether they were configured by UTA or not. In such a case, review the information in the comment and manually modify or add the values that have not been automatically configured.