[Testbox 4.5.0+5] Code Coverage Display Question

How do I get the TestBox code coverage section to show me the full report? I’d like to see something similar to what is shown in the TestBox documentation like this:

(Running Code Coverage - TestBox : Behavior Driven Development (BDD))

However, mine looks like this:

Note: I have updated my /tests/ folder’s application.cfc, index.cfm, and runner.cfm with the latest version from the Coldbox advanced script template as of today. I do have a licensed copy of Fusionreactor running.

It’s also strange that the files with best coverage include items that are blacklisted in runner.cfm:

<cfparam name="url.coverageBlacklist" default="/testbox,/coldbox,/tests,/modules,Application.cfc,/index.cfm">

Maybe I’m confused about the right way to configure code coverage?

@DaveL The code coverage report is stored in a different location as it is big. So the test harness gives you a snapshot only. The setting that controls the output directory is this:

<cfparam name="url.coverageBrowserOutputDir"        default="#expandPath( '/tests/results/coverageReport' )#">

Once the tests run the coverage reports will be dumped there.

1 Like

Thanks, @lmajano. I do see my runner.cfm has url.coverageBrowserOutputDir set to the default you mentioned but the folder is empty except for the “results_go_here.txt” file.

<cfparam name="url.coverageEnabled"					default="true">
<cfparam name="url.coveragePathToCapture"			default="#expandPath( '/root' )#">
<cfparam name="url.coverageWhitelist"				default="">
<cfparam name="url.coverageBlacklist"				default="/testbox,/coldbox,/tests,/modules,Application.cfc,/index.cfm">
<cfparam name="url.coverageBrowserOutputDir"		default="#expandPath( '/tests/results/coverageReport' )#">

Is there a good way to troubleshoot or debug why the report won’t generate?

The coverageBrowserOutputDir isn’t commented out or anything, right? Also, that cfparam only fires if the URl var doesn’t already exist. Is it possible it’s been set explicitly to an empty string somewhere else?

Add a dump/abort into the processCodeBrowser() function inside the testbox/system/coverage/CoverageService.cfc.

// Only generate browser if there's a generation path specified
if ( len( opts.browser.outputDir ) ) {
	var codeBrowser = new browser.CodeBrowser( opts.coverageTresholds );
	codeBrowser.generateBrowser( qryCoverageData, stats, opts.browser.outputDir );
	return opts.browser.outputDir;

If opts.browser.outputDir is an empty string, you can work backwards to figure out why. The default options are configured in the setDefaultOptions() method in the same CFC.

PLEASE NOTE: whatever runner you are using MUST PASS the coverage options explicitly to the testbox object. If you have built a custom runner that manually instantiates TestBox and doesn’t rely on the core testbox/system/runners/HTMLRunner.cfm, then you will need to manually pass those options.

testbox = new testbox.system.TestBox(
	labels   = url.labels,
	excludes = url.excludes,
	options  =  {
		coverage : {
			enabled       	: url.coverageEnabled,
			pathToCapture 	: url.coveragePathToCapture,
			whitelist     	: url.coverageWhitelist,
			blacklist     	: url.coverageBlacklist,
			sonarQube     	: {
				XMLOutputPath : url.coverageSonarQubeXMLOutputPath
			browser			: {
				outputDir : url.coverageBrowserOutputDir
1 Like

Thanks, Brad for the insight. The information you shared is very helpful. I am in the midst of troubleshooting and will report back when I have an update.