Running code coverage with a service entry point

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. Set a service entry point.
    Set a service entry point
    A service entry point is added to the IBM i Service Entry Points view.
    Service entry point added
  4. Set the service entry point to code coverage mode. Right-click the service entry point and select Code Coverage Mode. Alternatively, select the Code Coverage toolbar button in the view toolbar button. Note that the default mode for service entry points is debug mode. If you restart the IDE, the mode will be reset to debug mode.
    Set code coverage mode
  5. Optional: Edit the configuration if you want to modify the default code coverage parameters.
    1. Open the launch configuration. Right-click the service entry point and select Open Launch Configuration. The edit configuration dialog opens.
      Open launch configuration
    2. Add any programs or service programs that are called by your main program. 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.
    3. Edit the configuration as necessary. For example, under What to Analyze, you can specify the debug view used for analysis. 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 Apply and Close to save the configuration and return to the IBM i Service Entry Points view.
  7. In a 5250 terminal, call your main program. The service entry point configuration that you created will listen for the program to start.
    Call main program from 5250 terminal

    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.

    Status bar indicates that code coverage is running.

    If the program is interactive, it opens in the 5250 terminal and is ready for running tests.

    5250 running program

  8. For interactive programs, use the program according to your test procedures, then exit the program
  9. For batch programs, wait until the program is finished running. After the program is exited, a workbench report is opened and an item summarizing the coverage is added to the Code Coverage Results view.
    Code coverage results

Feedback