Set Coverage, Set("Coverage"), _Coverage

These cool features let you keep track of what code has been executed.

Usage

SET COVERAGE TO [ cFileName [ ADDITIVE ] ]
cFileName = SET( "COVERAGE" )
_COVERAGE = cCoverageApp 
cCoverageApp = _COVERAGE
DO (_COVERAGE) [ WITH cLogFile [, lHide ] [, cAddIn ] ]

Parameter

Value

Meaning

cFileName

Character

The name of a file to hold the coverage log.

Omitted

Turn off coverage logging.

cCoverageApp

Character

The program file to use to analyze a coverage log.

cLogFile

Character

The name of the file containing the coverage information to process. (The cFileName from SET COVERAGE.)

lHide

.F. or omitted

The Coverage Analyzer is displayed.

.T.

The Coverage Analyzer is hidden.

cAddIn

Character

The path and file name of an add-in utility.

Omitted

No add-in is specified.


Code coverage was introduced as a partially completed feature in VFP 5.0. While the code coverage logging worked most of the time, Microsoft documented but failed to ship a code coverage analyzer. In addition, there were problems with incorrectly reported form and class methods in version 5.0. Coverage became fully functional in VFP 6.The idea behind code coverage is to document every line of code that gets executed in a routine to ensure that all cases have been tested as part of your testing routine. The first step is logging. Issue SET COVERAGE TO YourFileName to begin the process. Each line of code that executes adds a line to this ASCII text file, recording the file name, line, procedure, class and amount of time to execute. When your routine has finished, issue SET COVERAGE TO with no argument to stop recording and close the file. If you want to add to the same file, use the ADDITIVE keyword.Now that you have this humongous text file, what to do with it? Run the code coverage analyzer, available on the Tools menu, to read the file and analyze the results.The Code Coverage Analyzer is actually two pieces—an engine and an application. The engine does the heavy lifting of parsing the log file, while the application presents the user interface. Realize that you can use the engine, but develop your own interface, to draw out the statistics you need. You could write your own components to do this, or you could consider writing an add-in. Your add-in can be a program, form, APP, EXE, menu or query. You pass the name of your add-in to the Analyzer, and it is invoked after the Analyzer has been instantiated. An object reference to the Analyzer tool is passed to your add-in. At this point, your routine can do whatever it needs to do—change the file to be parsed, add controls to the analyzer form, or present your own form instead. Fortunately, Microsoft has included well-commented source code for all parts of the Coverage application in the Tools\XSource directory and documented the PEMs of the Engine object in Help, so writing add-ins shouldn't be too difficult.

Example

SET COVERAGE TO MYCOVER.LOG
DO MYCODE
SET COVERAGE TO
DO (_COVERAGE) WITH "MYCOVER.LOG"

Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .