User-defined test cases can often be defined by modifying automatically-generated test cases.
To modify an existing test case:
- In the Test Case Explorer or in the project tree, locate the test suite file that C++test generated.
- By default, automatically-generated test classes are saved in the
tests/autogenerated
directory within the tested project. - To check where C++test is saving the test suite files, open the Test Configurations dialog, select the Test Configuration that was used for the test run that generated the tests, then review the value in the Generation> Test Suite tab’s Test suite output file and layout field (see Customizing Generation Options for details).
- By default, automatically-generated test classes are saved in the
- Double-click the node that represents the generated test class you want to modify. The generated test class file will open in an editor.
- Modify the test case as needed. You can...
- Use standard C or C++ code, the macros described in C/C++test API Documentation, the routines described in Available Test Functions, and the postconditions described in Test Case Post-Condition Macros.
- 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. Included test suites (the test suite type used for autogenerated test suites) do not need any headers included, unless there are types used that are not visible in the original tested source file. For example, additional headers might need to be included when you are modifying generated tests to include a test factory, etc.
- 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 backtrace to the source file to which this test suite is related. Only the selected test suite(s) will be executed.
4. Save the modified file.