How to make a pester test script validate that I had filled in a help template completely?

36 views
Skip to first unread message

Peter Taylor

unread,
Nov 19, 2016, 5:51:19 PM11/19/16
to Pester
Hi all,

I'm a newbie with pester and would like ask this group a question as I am not sure how to go about setting up an "It" test condition for an idea of mine.

How would I go about validating in my test script I have filled in the help template sections as using the test driven development will want to build up writing few functions from start up and ensuring I had made or populated some help descriptions over time.

<#
    .SYNOPSIS
    .DESCRIPTION
   .PARAMETER Code
   .PARAMETER Advanced
   .EXAMPLE
   etc
#>

Also wondering if anyone knows which Powershell command can make/generate the help template.

Thanks and kind regards,
Peter.

Chris Dent

unread,
Nov 20, 2016, 4:19:45 AM11/20/16
to Peter Taylor, Pester
I can't comment on the options available to build the function framework for you, I don't use any of them.

You can have a copy of some pester tests I have to use as a starting point:

$ReservedParameterNames = ([System.Management.Automation.Internal.CommonParameters]).GetProperties() | Select-Object -ExpandProperty Name
$ReservedParameterNames += ([System.Management.Automation.Internal.ShouldProcessParameters]).GetProperties() | Select-Object -ExpandProperty Name

Describe 'Function help content' {
    Get-Command -Module $ModuleName | ForEach-Object {
        $CommandInfo = $_
        $HelpContent = Get-Help $CommandInfo.Name -Full

        Context $CommandInfo.Name {
            It 'Must have a synopsis' {
                $HelpContent.synopsis | Should Not BeNullOrEmpty
            }

            It 'Must have a description' {
                $HelpContent.description.text | Should Not BeNullOrEmpty
            }

    $CommandInfo.Parameters.Values | Where-Object Name -notin $ReservedParameterNames | ForEach-Object {
        It "Must have a description for Parameters\$($_.Name)" {
            (Get-Help $CommandInfo.Name -Parameter $_.Name).description.Text | Should Not BeNullOrEmpty
        }
    }

    if ($CommandInfo.Name -match '-') {
        It 'Must have at least 1 example' {
            ($HelpContent.examples.example | Measure-Object).Count | Should BeGreaterThan 0
        }
    }
}

--
You received this message because you are subscribed to the Google Groups "Pester" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pester+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wojciech Sciesinski

unread,
Nov 20, 2016, 9:53:48 AM11/20/16
to Pester
Hi,
you can use tests described
http://www.lazywinadmin.com/2016/05/using-pester-to-test-your-comment-based.html authored by François-Xavier Cat fxcat[at]lazywinadmin[dot]com

Please read my comment for the post - yesterday I've found a bug what is not addressed yet.
Reply all
Reply to author
Forward
0 new messages