Page tree

Skip to end of metadata
Go to start of metadata

You will need to generate stubs to isolate one or more files from the rest of the code if you want to run tests in File Scope mode. Our goal in this exercise is to run unit tests on ATM.cxx in isolation from all other files in the project.

Compare Stubs Generated for File and Project Scope

  1. Right-click the Stubs directory in the project tree and choose Delete from the shortcut menu.
  2. If you have not already done so, create the Generate Stubs (File Scope) and Generate Stubs (Project Scope) configurations as described in Exercise 4.
  3. Select ATM.cxx, then run the "Generate Stubs (File Scope)" Test Configuration.
  4. Click the Stubs tab.
    • Original definitions will be used for functionality within the test scope.
    • Auto stubs will be used for functionality outside the test scope.

       

  5. For comparison, delete the Stubs directory in the project tree and run the Generate Stubs (Project Scope) configuration with ATM.cxx selected (optional).
  6. Click the Stubs tab and note that:
    • Original definitions will be used for all functionality needed.
    • No stubs are generated.
  7. Repeat steps 1-3 to generate stubs for ATM.cxx before continuing to the next section of the exercise.

Create and Execute Run Unit Tests (File Scope) Test Configuration

  1. Open the Test Configurations window and duplicate User-defined> Run Unit Tests (Project Scope).
  2. Open the Execution> Symbols tab and disable Use symbols from additional project files.
  3. Rename the configuration Run Unit Tests (File Scope).
  4. Apply changes and close the Test Configurations window.
    • In projects that contain multiple source files, you can select a single file, a set of files, or the entire project and test in file scope.
    • Any functionality that is outside the selected scope will need to be stubbed out.
  5. Select ATM.cxx in the project tree as the test scope.
  6. Choose Parasoft> Test Using> User-Defined> Run Unit Tests (File Scope).
  7. Notice in the Test Progress tab that only one file was tested with the 6 associated unit tests.

 

     

 

Execute File Scope Unit Tests on Source and Header Files

If you want to include header files, you must generate test cases for the contained functionality, generate stubs as necessary, and then run the unit tests.

  1. In the project tree, select ATM.cxx and the Header Filesnode (Ctrl-click to select multiple items).

  2. Choose Parasoft> Test Using> User-Defined> Generate Unit Tests - 2 to create test suites for Account.hxx and BaseDisplay.hxx.

     

     

  3. Select ATM.cxx and theHeader Filesnode in project tree (Ctrl-click to select more than one item). This will set ATM.cxx, Account.hxx, and BaseDisplay.hxx as the scope.

  4. Run the stub generation configuration for file scope testing by choosing Parasoft> Test Using> User-Defined> Generate Stubs (File Scope).

  5. Select ATM.cxx and the Header Filesnode in project tree to set the scope.

  6. Run unit tests using the file scope configuration by choosing Parasoft> Test Using> User-Defined> Run Unit Tests (File Scope).

     

     

Notice in the Test Progress tab that we now executed 21 test cases. We will address the execution results in later exercises.

  • No labels