Create the Generate Unit Tests configuration

  1. Choose Parasoft> Test Configurations to open the Test Configurations dialog.
  2. From the test configuration tree, choose Builtin> Unit Testing and right-click Generate Unit Tests
  3. Choose Duplicate from the shortcut menu to copy the configuration to the User-defined category.
  4. Select the duplicate configuration and click the Generation tab
  5. In the General tab, confirm the following default settings are selected or enabled:
    • Without test suites.
    • With out-of-date test suites.
    • With up-to-date test suites.
    • Public/global access functions.
    • Set the Max. number of generated test cases (per function) to 2. The default for this setting is 10, but you should generate a few test cases per function to begin.
      This is to reduce the number of test cases that need to be reviewed until you become familiar with the unit tests in C++ test.



6. In the Generation> Test suite tab, confirm that the following default settings are selected or enabled:

    • Test suite output file and layout should generate unit tests in a tests/autogenerated directory: ${project_loc}/tests/autogenerated/${file_loc_rel}/TestSuite_${file_base_name}_${file_ext}.${test_ext}.
    • Add tests for functions without tests.
    • Use full project path.



7. In the Generation> Test case tab, confirm that the following default settings are selected or enabled:

    • Initialize global variables as test pre-conditions.
    • Use heuristics for input values.
    • Use non-public class members in pre/post-conditions.
    • Use null values for pointers.
    • Use factory functions.
    • Create object on Stack.
    • Insert code to report test case outcomes
    • Display first element of a simple type pointer allocation.



8. Rename the configuration Generate Unit Tests - 2 tests.

9. Click Apply to save any changes and click Close.

Unit test generation is only applicable to source files. Test suites will be generated for header files only if they are referenced by a source file in the scope of the Test Configuration execution. However, if the header files referenced are not in the scope of the test case generation, no tests will be generated for the header files.

Run and review the test generation configuration

  1. Click ATM.cxx in the file tree to set the file as the test scope.
  2. Choose Parasoft> Test Using> User-Defined> Generate Unit Tests - 2 tests to generate a test suite for ATM.cxx.
  3. Click the Generate Unit Tests - 2 tab (Test Progress tab)  and review the summary of the test configuration execution.
  4. Expand the Scope and Generation sections to view additional summary information. We rec-ommend dragging the Test Progress tab to the far right side of the GUI.
     


a. Choose Window> Show View> Other> General> Project Explorer to open the project file tree (if not already open)

b. Expand the newly created ATM> tests> autogenerated directory.


c. Double-click TestSuite_ATM_cxx.cpp to open the associated test suite’s source file in the editor window. See Extending and Modifying the Test Suite for complete details about test suites.


  • No labels