In this section:
Recommendations for test improvements are displayed in the Recommendations view after tests are executed (see Configuring Preferences for information how to specify which recommendations UTA will generate). By default, all recommendations generated during the run are displayed, but you can filter out specific recommendations by selecting a category from the drop-down menu at the top of the Recommendations view:
Recommendations include action links and icons that help you navigate the test code and introduce changes.
The set of links and icons displayed may vary between recommendations, depending on the recommendation type, the test type, and the test code. Typically, most recommendations include:
Most action link automatically update you test code. For example, Uncomment removes specific comment markers in test templates generated by UTA, Remove Assertion deletes the line with an unnecessary assertion, and Clone test makes a copy of an existing test case. Some action links help you navigate or analyze rather than modify your test code, including the Track[method_name] action link which detects values that may need to be asserted; see Tracking Object Changes and Creating Assertions).
UTA displays recommendations for test code that was analyzed when the tests are run. If you change your code after test execution, recommendations may not be up to date, and the action links may not be applied appropriately. |
This section shows several examples of Unit Test Assistant recommendations and how they can be used to improve the quality of your test.
UTA detected that the test does not contain any assertions. Typically, this may happen when you create a new test with UTA and leave the default UTA assertions commented.
Remedy: You can do one of the following:
UTA detected assertions that failed during the test run, because the asserted value was different than expected.
Remedy: You can do one of the following:
assertTrue
with assertFalse
.If you run a Spring test, the Invert Assertion action link is not available. Depending on the assertion type, you can automatically update your test using one of the following action links:
UTA detected a system property that was added during the test run, but was not removed after execution. As a result, all subsequent tests will have access to that property, which may create dependencies between tests and prevent you from running them in isolation.
Remedy: Ensure that the system properties that were added or modified during a test run are removed or restored after execution.
UTA detected an additional thread that was active during the test run. Additional threads may affect test stability and cause random failures.
Remedy: Avoid writing test cases with side threads or ensure that they do not affect test results.
UTA detected a new file that was created during the test run, but was not removed after execution. This may affect subsequent test runs or other tests, as well as hide potential problems within the application, such as resource leaks.
Remedy: Ensure that the files created by the test are removed before the end of the test run.
UTA detected a static field that was modified during the test run. This may affect subsequent test runs, as well as other tests.
Remedy: Avoid writing test cases that change static fields during execution or ensure that the changes do not affect test results.
This recommendation is displayed only for static fields modified by static methods whose names follow the camel case convention and start with set, for example, |
The time limit that was specified when multiple tests were created (see Creating Multiple Unit Tests) has been exceeded.
Remedy: Manually modify the test to reduce its execution time or set a new timeout by modifying the value in the test code:
UTA detected code that is not covered. Click Go to navigate to the uncovered code.
Remedy: You can do one of the following to cover the code:
See Increasing Code Coverage for details.
See Recommendation Types for information about the types of recommendations UTA can display.