Versions Compared

Key

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

Unit Test Assistant can help you create parameterized test cases to test individual methods against different arguments

...

. Test cases can be added with the following UTA options:

  • Parameterized - Available in the UTA interface. This option allows you to add test templates for individual methods selected in the editor. The generated templates need to be manually modified and completed with parameterization data.
  • Add test case(s) - Available in the UTA interface and the Eclipse context menu. This option allows you to add multiple test cases for methods selected in the editor or for files and packages selected in the Eclipse Project Explorer. If your tests are created with the JUnitParams framework, you can configure input data that will be used when test cases are generated using this option; see Configuring Preferences for details.
Info

Ensure that the desired framework for creating parameterized tests is configured (see Configuring Preferences).

Using the Parameterized option

  1. If the Unit Test Assistant View is not already open, choose Parasoft> Show View> Unit Test Assistant from the Eclipse menu bar.
  2. Select the method in the editor.
  3. Click the Parameterized button.
    Image Removed
    Image Added
  4. Complete the test template with parameters and modify the default UTA values.




  5. Run the test with Unit Test Assistant to collect coverage information and recommendations for possible improvements (see Executing Unit Tests with Unit Test Assistant).

Using the Add test case(s) option

  1. If the Unit Test Assistant View is not already open, choose Parasoft> Show View> Unit Test Assistant from the Eclipse menu bar.
  2. Select the method in the editor.
  3. Click the Add test case(s) button to open the Unit Test Assistant dialog.
    Image Added
  4. Enable the Parameterized option.
    Image Added

  5. (JUnitParams only) If you use the JUnitParams framework, customize the following options:
    - The maximum number of parameter sets created for one test case specifies the maximum number of rows with parameter variants that will be created for one test case.
    - Generate test data to specifies where the test cases will be saved. Choose Code or CSV from the drop-down menu. The default is Code. 

    Info

    If you want to save test data in the CSV format, ensure that the JUnitParams library is added to your Eclipse project.

  6. Select the methods you want to create test cases for.
  7. Click OK.
  8. View the tests to modify the values and uncomment sample assertions. If you use the JUnitParams framework, your test cases will include the preconfigured parametrization data (see Configuring Preferences to view and customize the settings).
  9. Run the test with UTA to collect coverage information and recommendations for possible improvements (see Executing Unit Tests with Unit Test Assistant).

Alternatively, you can add test cases using the Eclipse context menu:

  1. Right-click a file(s) or package(es) in the Project Explorer.
  2. Click Add test case(s).
    Image Added

If you select more than one file or a package(s), the Unit Test Assistant dialog will not display individual methods. Test cases will be added to all testable files whose corresponding test classes have not been created. UTA will skip the files that are not testable or whose corresponding test classes already exist.