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
- Right-click the Stubs directory in the project tree and choose Delete from the shortcut menu.
- If you have not already done so, create the Generate Stubs (File Scope) and Generate Stubs (Project Scope) configurations as described in Exercise 4.
- Select ATM.cxx, then run the "Generate Stubs (File Scope)" Test Configuration.
- 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.
- For comparison, delete the Stubs directory in the project tree and run the Generate Stubs (Project Scope) configuration with ATM.cxx selected (optional).
- Click the Stubs tab and note that:
- Original definitions will be used for all functionality needed.
- No stubs are generated.
- 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
- Open the Test Configurations window and duplicate User-defined> Run Unit Tests (Project Scope).
- Open the Execution> Symbols tab and disable Use symbols from additional project files.
- Rename the configuration Run Unit Tests (File Scope).
- 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.
- Select ATM.cxx in the project tree as the test scope.
- Choose Parasoft> Test Using> User-Defined> Run Unit Tests (File Scope).
- 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.
In the project tree, select ATM.cxx and the includenode (Ctrl-click to select multiple items).
Choose Parasoft> Test Using> User-Defined> Generate Unit Tests - 2 to create test suites for Account.hxx and BaseDisplay.hxx.
Select ATM.cxx and theincludenode in project tree (Ctrl-click to select more than one item). This will set ATM.cxx, Account.hxx, and BaseDisplay.hxx as the scope.
Run the stub generation configuration for file scope testing by choosing Parasoft> Test Using> User-Defined> Generate Stubs (File Scope).
Select ATM.cxx and the includenode in project tree to set the scope.
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.