In this section:

Introduction

Unit Test Assistant can help you create parameterized test cases to test methods against different arguments. Test cases can be added with the Parameterized option available in the Unit Test Assistant view. 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.

Test parametrization is supported for JUnit 4 and 5. UTA generates parameterized tests using the testing framework and parameterization type configured in Preferences (see Configuring Preferences).

Creating Parameterized Tests

  1. Choose Parasoft> Preferences> Unit Test Assistant.
  2. Enable the Parameterized tests> Enable creation actions option.
  3. Select a method in the editor.
  4. Click the Parameterized action link in the Unit Test Assistant view.
  5. Complete the test template with parameters and modify the default UTA values.
  6. Run the test with Unit Test Assistant to collect coverage information and recommendations for possible improvements (see Executing Unit Tests with Unit Test Assistant).

Creating Parameterized Tests for Private Methods

UTA allows you to create parameterized tests for private methods to achieve a higher code coverage rate.

  1. Choose Parasoft> Preferences> Unit Test Assistant.
  2. Enable the Parameterized tests> Enable creation actions option.
  3. Enable the Test creation options> Create tests for private methods option.
  4. Select a private method in the editor.
  5. Click the Parameterized private action link to create a test for the selected method.

By default, the Create tests for private methods option is disabled, since the industry best practice is to test private methods by creating tests for the accessible methods that call them, rather than by creating tests for private methods directly.

Cloning as a Parameterized Test

You can create a parameterized JUnit 5 test from an existing non-parameterized test from the UTA view.

Cloning an existing test as a parameterized test does not affect the original test. The existing literal values that are passed to the method under test will become test parameters. The values will be moved into a single row of data for the new test.

  • No labels