Code Coverage Analysis for Pester (Feedback Request)

(12-Jul-2014 Edit: This article is now quite a bit out of date. The Coverage Analysis feature has since been merged into Pester’s Beta branch, and some of the details of how it works have changed as well.)

I’m working on a new feature for Pester which provide a report on code coverage, in addition to what Pester already does when running the tests:

I’m looking for some feedback on how to build the user experience. It currently works by adding a single new parameter to Invoke-Pester (currently called -Coverage, but this may change). The Coverage parameter works a little bit like the -Property parameter on Select-Object, where you can either pass in a simple string value, or a hashtable which defines more options. Right now, the hashtable allows you to specify a specific range of lines within a file to analyze:

# Report on all of the ps1 / psm1 files in a folder
Invoke-Pester -Coverage .\*.ps1, .\*.psm1

# Report on lines 50 through 80 in a single file (perhaps if you want to
# show a coverage analysis for a single function)
Invoke-Pester -Coverage @{ Path = '.\MyModule.psm1'; StartLine = 50; EndLine = 80 }

# Combining strings and hashtables is fine
Invoke-Pester -Coverage @{ Path = '.\MyModule.psm1'; StartLine = 50; EndLine = 80 }, '.\MyOtherFile.ps1'

I plan to add support for analyzing functions by name, instead of having to use line number ranges, but right now I’m just curious about how user-friendly this approach is. If you think the current behavior is confusing, how would you improve it?

When you use this feature, it gives you a report containing the number of commands that were analyzed, the percentage of them that were executed by the test, and a table displaying the file path, line number and text of any commands that were missed. Right now this report goes to the console, but I’ll add it to the -Passthru output object at some point as well.


About Dave Wyatt

Microsoft MVP (PowerShell), IT professional.
This entry was posted in PowerShell and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s