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.
2. Open the Test Suite Wizard as follows:
- Select your tests directory in the project tree.
Choose Parasoft> Wizards> Create New Test Suite.A wizard will open.
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_CONTEXTmacro, 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, thenchoose Parasoft> C++test> Test Suite> Add Test Case Template. 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 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_CONTEXTmacro, 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.