In this section:

Configuring General Options

  1. Choose Parasoft> Preferences> Unit Test Assistant in the menu bar.


  2. Specify where tests should be saved in the Tests location field. You can choose a preset pattern or enter a custom pattern.


    You can select an option from a drop-down menu or customize the pattern with the following predefined variables:
    ${class_name} - The name of the tested class.
    ${package_name} - The name of the package that includes the tested class.
    ${source_folder} - The name of the folder that contains the source files of the project.
    ${project_name} - The name of the project that includes the tested class.
    ${test_kind} - The name of the test type, which will be added to the file name. This variable can take the following values:
              - Spring - Separates Spring tests from other tests in JUnit 4 and 5.
              - Parameterized - Separates parameterized tests from regular test in JUnit 4. In JUnit 5, regular and parameterized test cases are added to the same file.
  3. Select the testing framework UTA will use to create new tests.
    If you choose JUnit 4, you need to select the framework for creating parameterized test cases.

    If you choose JUnit 5, Junit 5 Parameterized will automatically be enabled for creating parameterized test cases.

    You can click Parameterization Settings to configure input data for creating parameterized test cases with the Add test case(s) option (see Creating a Parameterized Unit Test).

    You can customize the default list of values by selecting a data type from the Select type drop-down menu and adding, editing or removing the values in the list. The Find field allows you to conveniently search for a particular value.

    When you add new values, the characters must match the character encoding that will be used to save the files to ensure that the files are properly generated. 

  4. Enable or disable the test creation options.

    Generate sample assertions - if enabled, UTA will automatically generate assertion templates when a test case is created. Assertions will be created as comments in code; see Creating a Basic Unit Test for details. This option is enabled by default.
    Create tests for private methods - if enabled, UTA will display action links that allow you to create regular, parameterized, and Spring unit tests for private methods. This option is disabled by default.

  5. Enable or disable the Automatically discover tagged factory methods option. If enabled, UTA will automatically:
    - scan all projects for factory methods on the IDE startup
    - search for updates to factory methods when your project is modified (for example, when you create or delete a Java file or project).
    See Configuring Factory Methods for details. This option is enabled by default.


        

  6. (optional) Specify the attributes that will be included in the ContextConfiguration annotation when a Spring test is created; see Creating a Spring Unit Test.

        

  7. Specify which recommendations you want UTA to display after test execution.

    Additional threads - detects side threads, which may impact the state of your test.
    Assertions for inaccessible fields - detects inaccessible fields that have been modified during execution and generates assertion templates.
    Files created - detects files that were created during the test run, but were not removed after execution. 
    Mockable invocations - detects calls to mock objects that can be modified to ensure proper test isolation.
    No assertions - detects when no assertions have been made.
    Static fields changed - detects when static fields have been modified during test execution.
    Mockable static invocations (JUnit 4 only, requires PowerMock) - detects calls to the static methods that are configured to be mocked with PowerMock (see Configuring Mocking Options)
    System properties changed - detects system properties that were modified during the test run, but not restored after execution.
    Uncovered code - detects uncovered blocks of code.

    See Executing Unit Tests with Unit Test Assistant for examples of recommendations displayed by UTA.

  8. Specify the limits for collecting data during execution.



    Maximum method call depth - Specifies the maximum depth of method calls during analysis.
    Maximum number of method calls made from a single method - Specifies the maximum number of sub-method calls from a single method. 
    Maximum total number of method calls -  Specifies the maximum number of all method calls during analysis.
      

  9. Click Apply.

Configuring Mocking Options

  1. Choose Parasoft> Preferences> Unit Test Assistant> Mocking to configure mocking options.

      
  2. Select the Enabled check box to enable mocking objects during test creation and execution.
  3. Enable or disable the Use helper methods for mocks option. If enabled, generated tests classes will separate regular test methods from helper methods that prepare objects but do not make assertions. 
  4. Specify the mocking framework that you use.

    (info) The options are only available if you configured UTA to use JUnit 4 (see Configuring General Options), because PowerMock currently does not support JUnit 5. If you create your tests with JUnit 5, the Mockito framework will be used by default.

    Mockito version

    UTA automatically detects the Mockito version you are using and creates unit tests following the detected version of the API. If Mockito is not detected, UTA creates tests using Mockito 2.

  5. If you select PowerMock, specify a list of static methods and constructors to be mocked. Click New to add a new method or pattern. Use qualified method names and wildcards (*) to match patterns. The patterns that end with .* or  <init> will be matched with constructors. For example, the following configuration will mock:
    - all constructors in all classes whose names end with "Service",
    - all static methods and constructors in all DAO classes in all sub-packages of "com.example",
    - all methods of the InternalUtil class.



    If the specified pattern matches all methods of a class, UTA will use the mockStatic() method which mocks all static methods of a class. Otherwise, the spy() method will be used to mock individual methods that are specified. For details about the mockStatic() and spy() methods, see https://github.com/powermock/powermock/wiki/Mockito#usage

    Only the static methods and constructors specified in the table will be mocked. UTA will automatically add mocks to test templates during test creation, or display recommendations that will help you add mocks after your tests are run (see Creating Mocks).
      
  6. Click Apply.


  • No labels