Running code coverage on batch applications

Running code coverage provides insight into how well your test cases are exercising your IBM i applications by reporting results showing the percentage of lines in your code run by a test case as well as line by line coverage details. You can run code coverage for any IBM i application that you can debug.

Procedure

  1. Compile your program with the source debug option.
    Note:
    • You need to use one of the DBGVIEW(*ALL), DBGVIEW(*SOURCE), or DBGVIEW(*LIST) options.
    • Compiler optimization can affect the report of lines covered. For the most accurate results, compile with OPTIMIZE(*NONE).
    • If portions of the application do not have debug information, only those portions of the application with debug information are included in the code coverage report.
  2. Browse to your program under your connection in Remote Systems Explorer. If you want, you can create filters or add library list entries to facilitate finding your programs.
    Browse to your program
  3. Create a code coverage configuration for a batch program. Right-click the program and select Code Coverage (Prompt) > Batch
    Launch code coverage in batch mode
    A compiled code coverage configuration is created and opened in the Edit configuration and launch dialog.
    Code coverage configuration is opened
    Note: An alternative method to launch code coverage is right-click your program and select Code Coverage As > Batch. In this case, a configuration is created and the code coverage session is started without opening the Edit configuration and launch dialog. If your program is simple and does not require any additional set up such as adding called programs, this can be a convenient method for starting code coverage.
  4. Add any programs or service programs that are called by your main program. Under the What To Analyze tab, click the Add button to add additional called programs.
    Add called programs
    Called programs after they are added. The main program is selected.
    Called programs added. Main program selected.
  5. Edit the configuration as necessary. For example, under What to Analyze, you can specify the debug view used for analysis. Under How To Start, you can change the command used to start the application. Under Code Coverage, you can specify details such as whether coverage is on the Line or Procedure level. For more information about configurations, see Editing code coverage configurations.
  6. Click the Coverage button to start the code coverage session.
    Click Coverage button

    The status bar at the bottom of the IDE displays the message Running code coverage for PROGRAM_NAME. Where PROGRAM_NAME is the name of your program.

    Running code coverage message in status bar

    When the program completes, a workbench report is opened and an item summarizing the coverage is added to the Compiled Code Coverage Results view.

    Code coverage results


Feedback