User-defined test cases can often be defined by modifying automatically-generated test cases.

To modify an existing test case:

  1. 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).
  2. Double-click the node that represents the generated test class you want to modify. The generated test class file will open in an editor.
  3. Modify the test case as needed. You can...

      • 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.  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.

  • No labels