Adding New Test Suites
To add user-defined test cases:
- If you have not already done so, create a new directory for your tests.
- The test directory can be located anywhere, as long as it is visible in the project tree. By default, C++test expects tests to be stored in a subdirectory of the project’s tests directory. However, you can use a different location, as long as you modify the Test Configuration’s Test suite file search patterns setting (in the Execution> General tab) accordingly.
- If you do not want to store your tests within the project directory, you can add a folder that links to files stored elsewhere in your file system. To do this:
- Choose File> New> Folder (if this is not available, choose File> New> Other, select General> Folder, then click Next).
Click the Advanced button.
Enable the Link to folder in file system option.
Enter or browse to the location of your source files.
Click Finish.
- If you do not want to store your tests within the project directory, you can add a folder that links to files stored elsewhere in your file system. To do this:
- Select your tests directory in the project tree.
Right-click the selection, then choose New> Other from the shortcut menu.
A wizard will open.
с. Select Parasoft> C++test> Test Suite, then click Next.
3. Enter the test suite parameters in the Test Suite Wizard dialog. Available parameters are:
- Test suite name: Determines the test suite’s name.
- Test suite location: Determines the test suite’s location.
- Test suite file(s): Reports the path to the test suite file(s).
- Test suite language: Determines whether the test suite is implemented in C or C++.
- Tested file: Sets the test suite context to the specified tested source file. The specified file will be set as the
CPPTEST_CONTEXT
macro, which associates a given test suite file with a specified source file.- If a file was selected when you started the wizard, that file will be specified here.
- If a project was selected when you started the wizard, no context will be spec-ified, and the test suite will be at the project scope (which means it will only get executed if all tests for the project are run, or if it is selected as the test file). When it is selected as the test file (and does not have the CONTEXT) C++test assumes it has the project context, and prepares all files in the project to link against.
- Test suite mode: Determines whether the test suite is implemented as an included test suite, or a standalone test suite. C++test instruments both types of test suites; it can access private/protected class members.
- Included test suites are physically included in one of the generated test harness source files. "Included" test suites are combined with instrumented code and compiled to form a single object file. All automatically-generated test suites are included test suites. Additional header files can be included and macro definitions can be defined in original headers. However, included test suites do not need any headers included, unless there are types used that are not visible in the original tested source file. Typically, this is only necessary when you are modifying generated tests (e.g., to include a test factory, etc.).
- Standalone test suites are compiled separately and linked in with the test executable for the testable context. Any additional headers must be included directly in these test suites. Coverage information can be tracked for included headers.
4. (Optional) If you want to specify test cases at this point (i.e., so C++test registers them in the test suite and adds a skeletal framework for the tests), click Next, then use the controls to add test case names and specify the order in which you want them added.
5. Click Finish.
Adding Test Cases to an Existing Test Suite
To add a new test case to an existing test suite:
Select the test suite file in the project tree, or open it in the editor, thenright-click the selection, then choose Parasoft> C++test> Add Test Case Template from the shortcut menu.
Or, right-click a the test suite in the Test Case Explorer and choose Add New> Test Case Template.
- Enter a name for the test case. The new test case will be added, and the test suite will be modified accordingly.
- Open the test suite source file in the editor, enter test case definitions, and make additional modifications as needed. You can...
- Use standard C or C++ code, the macros described in C++test API Documentation, the routines described in Available Test Functions, and the postconditions described in Test Case Post-Condition Macros.
- The Content Assist feature help you add macros and postconditions. For instance, to add a postcondition template, type CPPTEST_POST_CONDITION, place your cursor after the N, press Ctrl + Space, then select the desired postcondition.To add an assertion template, type CPPTEST_ASSERT, place your cursor after the T, press Ctrl + Space, then select the desired assertion. Be sure to customize the added templates.
- The Content Assist feature help you add macros and postconditions. For instance, to add a postcondition template, type CPPTEST_POST_CONDITION, place your cursor after the N, press Ctrl + Space, then select the desired postcondition.To add an assertion template, type CPPTEST_ASSERT, place your cursor after the T, press Ctrl + Space, then select the desired assertion. Be sure to customize the added templates.
- Use include directives and macro definitions defined in header files.
- Prompt C++test to include additional files when building a test executable by using an #include directive.
- Change the test suite context by changing the
CPPTEST_CONTEXT
macro, which associates a given test suite file with a specified source file. Only one source file can be specified. If no context is specified, the test suite will be executed whenever the project is executed.- When a source file or directory is selected in a project tree (e.g. a source file) before test execution is started, C++test scans all test directories specified in the Test Configuration’s test search path. All test suites that match the selected context will be executed.
- If the entire project is selected, all test suites on the test path will be executed.
- If a test suite or single test is selected, the CONTEXT macro is used to back-trace to the source file to which this test suite is related. Only the selected test suite(s) will be executed.
- If relative paths are used, they must start with "./" or with "../".
4. Save the modified file.