In this section:

 

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,type ffs and press Ctrl+Space and add the following factory function.


  3. To add another factory function template,type ff and press Ctrl+Space.


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.

 

  • No labels