Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space ENGINES1031 and version 10.4.1

...

You can extend the analysis performed by UTA with the Track option that monitors the tracking actions that monitor an object and compares compare its state before and after the execution of a selected method. This gives you insight into how particular values changed during execution and helps you make relevant assertions. The following tracking actions are displayed in the Unit Test Assistant view:

  • Track [method_name]

...

  • - monitors a method call and displays available assertions in the Recommendations view. You can manually update your test with recommended assertions by applying a quick-fix (see Manually Creating Assertions).
  • Track and make assertions - monitors a method call and automatically applies all recommended assertions that are not already present. This option is not available for parameterized tests and tests that fail to run.

Tracking Object Changes

  1. Create a new test with UTA or open an existing test and click the test .
  2. Click a test method. If the test method's name is consistent with the name of the method under test, UTA will detect automatically identify the tested method and display the two tracking options: Track [method_name] button in the UTA interface that tracks the method call and Track and make assertions that tracks the method call and automatically creates assertions.


    Image RemovedImage Added

    To track an invocation of a method whose name is different than the test method name, select a specific method invocation in the editor. The UTA interface may will simultaneously display two action buttons that monitor Track [method_name] actions – allowing you to track both the automatically detected tested method and the selected method selected in the editor.
    Image Removed
    , and the Track and make assertions action to track update the selected method.

    Image Added
    Image Added
      
  3. Click one of the Track action links to Click the Track [method_name] button. UTA will run the test and display collect information about the values that changed during execution and may need to be asserted..
      
  4. View the information about object changes in the Recommendation and Variables tabs.
    The Recommendations tab displays information about recommended assertions, along with values that changed during execution. You can click the Highlight link to view individual recommendations in the execution flow.
    Image Removed
    The Variables tab displays information about values that were used during execution. The >> icon indicates values that changed.

  5. Analyze information in the UTA interface to decide which assertions you want to make.

Creating Assertions


  1. View the information about the available assertions in the Recommendations tab and add the assertions manually (see Manually Creating Assertions). This step is required if you do the tracking with the Track [method_name] action.

Anchor
Manually Creating Assertions
Manually Creating Assertions
Manually Creating Assertions

You can make assertions from both the Recommendations and the Variables tabsviews.

  • In the Recommendations tab view, click the Make assertions link quick-fix.
  • In the Variables tab view, right-click the value you want to assert and choose Make assertions.


    Alternatively, you can copy the value with the Copy option to manually complete the code.

...

You can enable or disable generating recommendations for inaccessible fields; see Configuring Preferences for details.

Creating Assertions for Multiple Tests

You can track and automatically create assertions for more than one test.

To create assertions for tests from the same class:

  1. Open the test class.
  2. Click anywhere outside any test methods.
    Image Added
       
  3. Click the Track and make assertions action in the Unit Test Assistant view.

To create assertions for tests from different classes, packages, and/or projects:

  1. Select the desired classes, packages, and/or projects in the Project Explorer.
  2. Choose Unit Testing> Track and make assertions from the context menu.
    Image Added

Assertions Tips and Tricks

  • If you create multiple tests with UTA, we recommend disabling the Generate sample assertionsoptions in UTA preferences to avoid redundant assertions in the final tests (see Configuring Preferences and Creating Multiple Unit Tests).
  • When using the Track and make assertions action, you may want to set the console verbosity level to High to view additional details about the assertion creation process (see Customizing Console Verbosity). The console will display the number of assertions created per test case and details about assertions that were not created.