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

...

  1. Choose Parasoft> Show View> Unit Test Assistant from the Eclipse menu bar to open the Unit Test Assistant interface.
  2. Select a Spring controller in the editor. UTA will analyze your code and display one or more options that are available for the selection. The following options may be displayed:
    - Regular Spring creates a test for the selected method.
    Parameterized Spring creates parameterized test cases. 
    - Add Spring test case(s) creates tests for multiple methods from the controller.
    Image RemovedImage Added
  3. Select one of the available options. If you choose Add Spring test case(s), select the methods you want to create test cases for when prompted, and click OK. See Creating Multiple Unit Tests for details.
  4. The generated test or tests include sample assertion templates and default UTA values. View the test(s) to uncomment the sample assertions and modify the values.

    Info

    Spring tests created with UTA do not include optional parameters. For example the following parameter will not be included:
    @RequestParam(value = "count", required = false)

  5. Run the test with UTA to collect coverage information and recommendations for possible improvements (see Executing Unit Tests with Unit Test Assistant). To facilitate finding handler method calls in the execution flow tree, most internal Spring calls are hidden.

Creating Spring Tests for Private Methods

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

  1. Enable the Create tests for private methods option in the UTA Preferences (see Configuring Preferences).
  2. Select a private Spring controller method in the editor.
  3. Choose one of the following options
    - Click Regular Spring private to create a regular test for the selected private method.
    - Click Parameterized Spring private to create a parameterized test for the selected private method.
    - Click Add Spring test case(s) to create tests for multiple methods from the controller, including the private methods.
    Image Added

(info) 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.

Configuring Spring tests with the ContextConfiguration Annotation

...