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

  1. If not already open, choose Parasoft> Show View> Unit Test Assistant from the Eclipse menu bar.
  2. 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.
  3. 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 

When you run a test, the JUnit view will automatically open and display general information about test run progress and status.

After test execution, the UTA view 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.

  • Double-click a tree node to highlight the code associated with that element in the editor. 
  • 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.



  • Right-click a node and choose Expand Children or Collapse Children to expand or collapse its children nodes.

     
  • Right-click a node that represents a static method or a constructor and choose one of the following mocking options:
    - Add Mockable Method Pattern - Adds the method or constructor to the list of static methods to be mocked with PowerMock (see Configuring Mocking Options).
    - Mock Static Method - Updates the code to mock the selected method call with the spy() method (see Configuring Mocking Options for details).
    Mock Constructor - Updates the code to mock the selected constructor.

    The mocking options require mocking to be enabled and PowerMock with Mockito to be selected as the mocking framework; see Configuring Mocking Options.

Recommendations and Variables

Recommendations for test improvements and variables associated with method calls are displayed in the right column. The total number of recommendations is displayed at the top of the Recommendations tab. You can customize what type of recommendations UTA will report; see Configuring Preferences for details.

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.

Recommendations include action links that help you navigate the test code and introduce changes. The action links that are displayed for each recommendation may vary depending on the recommendation type, the test type, and the test code. 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.

Recommendations can also include:

  • the Learn more... link which opens a page with details about individual recommendations,
  • the Track [method_name] action link which detects values that may need to be asserted; see Tracking Object Changes and Creating Assertions for more information,
  • action links that automatically update your test code (for example, Uncomment removes specific comment markers in test templates generated by UTA, and Remove Assertion deletes the line with an unnecessary assertion).

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 tab:

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.

No Assertions

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:

  • Uncomment the default assertions manually or with the Uncomment action link and modify the default values.
  • Click the Track [method_name] action link. UTA will run the test and display the values that may need to be asserted; see Tracking Object Changes and Creating Assertions for more information.
  • Manually modify the test and make assertions based on the green and red coverage markers that indicate the test execution flow.

Assertion Failure

UTA detected an assertion that failed during the test run, because the asserted value was different than expected.

Remedy: You can do one of the following:

  • Manually modify the assertion in the test code.
  • Click the Update Assertion action link to automatically replace the current value with the expected one.
  • Click the Invert Assertion link to automatically invert the assertion logic, for example, by replacing assertTrue with assertFalse.
  • Click the Remove Assertion link to remove the assertion from the test code.

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:

  • Update Assertion replaces the current value with the expected one. If the value to be updated is assigned to a local variable, the action link is available only if the value types match (for example, both values are of integer type).
  • Update status to: [...] updates the HTTP Status assertion.
  • Remove Assertion removes the assertion from the test code.

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 the system properties that were added or modified during a test run are removed or restored after execution.

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.

New 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.

Static Fields Changed

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, setStaticValue().

Timeout

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:


  • No labels