Introduction
Executing tests within Unit Test Assistant allows you to collect data about the execution flow and use this data to improve the test quality. UTA can analyze a test case during execution to identify issues and display recommendations on how the test can be enhanced. It also automatically collects coverage information for all tests run within the Unit Test Assistant interface.
Running Tests with Unit Test Assistant
- If not already open, choose Parasoft> Show View> Unit Test Assistant from the Eclipse menu bar.
- Specify the test(s) you want to execute. You can make a selection in the Package Explorer, open a test in the editor or select an element in a source file to automatically detect associated tests.
- In the UTA interface, click Run test[method_name] to run the test for the selected method or Run All to run all tests in the method's class.
Viewing Execution Results
JUnit View
When you run a test, the JUnit view will automatically open and display general information about test run progress and status.
UTA View
After test execution, the UTA interface displays execution details in a two-column view.
Execution Flow
Execution flow data is displayed in the left column as an expandable tree that helps you analyze execution flow and navigate your code.
- Right-click a node to view the navigation options.
Go To - Highlights the selected method call in the editor.
Go To Declaration - Navigates to the method declaration. - Double-click a tree node to highlight the code associated with that element in the editor.
Recommendations and Variables
Recommendations for test improvements and variables associated with method calls are displayed in the right column. Recommendations include action links that help you navigate the test and introduce changes. The links may vary depending on the recommendation type. However, all recommendations include:
- Go to - Highlights the code associated with the recommendation in the editor.
- Highlight - Highlights the issue in the execution flow displayed in the left column.
The Variables tab shows the values associated with method calls that can be used to compare the state of an object before and after a method call. See Tracking Object Changes and Creating Assertions for details.
Examples of Recommendations
This section shows several examples of Unit Test Assistant recommendations and how they can be used to improve the quality of your test. See Configuring Preferences to customize what type of recommendations UTA will report.
You can click the Learn more... link for details about individual recommendations.
Example 1 - System Properties Changed
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 system properties that were added or modified during a test run are removed or restored after execution.
Example 2 - Additional Threads
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.
Example 3 - Files Created
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.
Remedy: Ensure that the files created by the test are removed before the end of the test run.
0 Comments