Create a Unit Test Project and Test Program for Existing Code

Use this process if you are creating unit tests that are to call into existing application logic. Note that the application logic must be part of a Link Library or INT/GNT project in order to use this method.

The main benefit of this process is that the required linking from the test case(s) to the source code is generated automatically when the test program is created, and you are ready to start calling into the application logic. For ease of use, we recommend that you organize your solution/projects as described in Best Practice for Organizing Unit Test Projects when using this process.

  1. Ensure that the solution containing to application logic to be tested is open.
  2. Double-click the .cbl file containing the code on which to test.

    The COBOL code is displayed in the editor.

  3. Right-click anywhere in the editor, then select Create Unit Test.

    The Create Unit Test dialog box appears.

  4. Select the type of unit test to create - Program Test, Program Test (Data Driven), or Self Contained Unit Test, and then click Next.
  5. In the Test project field, click and either select <New Test Project> or select the name of an existing unit test project.
    Note: Self-contained unit test must be created in their own unit test project.
  6. If you selected <New Test Project>:
    1. In the New test project name field, type a name for the new project.
    2. In the Project location field, type the name for the new directory that the project files will be placed.
  7. In the New test program name field, type the name of the test program file (.cbl file) to contain your tests. (Not applicable for self-contained unit tests; the required name is created by default.)
    Important: Ensure that your test program name is unique in the context of the containing solution.
  8. Click Next.
  9. If you are adding a program test, select one or more entry points in the source code on which to base your test cases:
    1. In the Entry Point Name column, select the entry point that contains the code that you want to test.
    2. In the Test Case Name column, type a name for the test case.

      The name defaults to the entry point name prefixed with "Test".

    3. To add another test case, click Add New, and then repeat the previous steps.
    4. Click Finish.
  10. If you are adding a data driven test, select one entry point and the source file for a test case:
    1. In the Entry Point Name field, select an entry point that contains the code that you want to test.
    2. In the Test Data File field, click Browse and select the .CSV file to use for the tests.
      Note: We recommend that you do not select a data file that is already being used for data driven tests in test programs for other unit test projects in the same solution; ideally, you should use one data file for each test program - this can be a uniquely-named copy of an existing data file if required.

      The data file is copied into the project if it does not already exist.

    3. In the Test Data Delimiter field, select the delimiter used within the file.

      If the required delimiter is not listed, you can specify the correct one using metadata (MFU-MD-DD-DSV) within the test case.

    4. Click Finish.
    Note: For conventional unit tests, you can add further test cases once the test program has been created.

    The unit test project is created, which contains the specified test program, and then within that, the test case and test setup elements for each test case configured.

  11. If you are adding a self-contained test, add the name of the test case to be created:
    1. In the Test Case Name field, type the name of your first test case.

      This defaults to the name of the source program under test, prefixed with 'Test'.

    2. Click Finish.
Depending on the type of test program you selected, the following changes are made to the unit test project: