Versions Compared

Key

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

In this section:

Table of Contents

 

By default, C++test uses predefined strategies for initializing objects when generating test cases—e.g.,  characteristic values for integer types (0, 1, max, min, etc.), using constructors for class types, etc. By defining factory functions, you can provide additional initializers for types to be used in automatically-generated test cases and test cases created using the test case wizard.

  1. Open the ATM/ATM.cxx file in the editor.
  2. At the end of the source code,

    Conditional Content
    IDE: (VS)
    IDE: (VS)
    sv-attr:0A0102040159A975064F0FA35093CF150A0102040159A9821F79B94259645A41

    right-click on whitespace in the editor and choose Parasoft> C++test> Insert Snippet> C++test factory functions section

     and add the following factory function.


  3. To add another factory function template,

    Conditional Content
    IDE: (VS)
    IDE: (VS)
    sv-attr:0A0102040159A975064F0FA35093CF150A0102040159A9821F79B94259645A41

    right-click and choose Parasoft> C++test->Insert Snippet> C++test factory function template.


Create a "Generate Unit Tests" Test Configuration

  1. Choose Parasoft> Test Configurations to open the Test Configuration dialog.
  2. Select Built-in> Unit Testing and right-click Generate Unit Tests.
  3. Choose Duplicate from the shortcut menu to copy to the User-defined category.
  4. Open the Generation> General tab on the new user-defined configuration.
  5. For Generate tests for function access level, enable protected and private.



  6. Open the Generation> Test Case tab.
  7. Enable Use factory functions > Do not use other initializers for types with factory functions.



  8. Rename the new user-defined configuration to Generate Unit Tests - Factory Functions.
  9. Apply the changes made and close the Test Configurations window.

Run the Test Generation Configuration

  1. In the project tree, select ATM.cxx as the test scope.
  2. Choose Parasoft> Test Using> User-Defined> Generate Unit Tests - Factory Functions.
  3. Review the results. Note that some new test cases were generated for private methods of the ATM class.
  4. In the Test Case Explorer, open tests> autogenerated> TestSuite_ATM_cxx . . .  and double-click the test_makeDeposit_1 test case.
  5. Note that the Bank* and BaseDisplay* arguments of the ATM's constructor are initialized using the factory functions.