{"id":8754,"date":"2021-12-28T11:41:50","date_gmt":"2021-12-28T16:41:50","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=8754"},"modified":"2021-12-28T11:41:53","modified_gmt":"2021-12-28T16:41:53","slug":"accelerate-pester-test-development","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/","title":{"rendered":"Accelerate Pester Test Development"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"alignleft size-full\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/pexels-thisisengineering-3862132.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"213\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/pexels-thisisengineering-3862132.jpg\" alt=\"pexels-thisisengineering-3862132\" class=\"wp-image-8755\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/pexels-thisisengineering-3862132.jpg 320w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/pexels-thisisengineering-3862132-300x200.jpg 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>The other day I <a href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8750\/powershell-plans-for-2022\/\" target=\"_blank\" rel=\"noreferrer noopener\">shared my PowerShell plans for 2022<\/a>. And needless to say, I didn't wait to dig in. I am working on a new module and since it won't be published until next month, I went ahead and marked it as Core only. I also started writing a set of Pester 5.x tests for it. Naturally, this is forcing me to revisit the Pester documentation and re-learn how to construct a Pester test.<\/p>\n\n\n\n<p>During this process, I decided I needed to help myself speed up the test writing phase. I have a standard set of tests that I like to use for functions in my module. But copying and pasting code snippets is tedious. I know I could create a set of VS Code snippets, but that feels limiting and I'd have to make sure the snippets are available on all systems where I might be running VS Code. Instead, I wrote a PowerShell function to accelerate developing Pester 5.x tests.<\/p>\n\n\n\n<p>My function takes a module and extracts all of the public exported functions. For each function, it creates a set of standard Pester assertions. These are the baseline or boilerplate tests that I always want to run for each function. Each function is wrapped in a Describe block. Although, I can opt for a Context block instead. This command will also insert tags. Note that my code for the tag insertion relies on the ternary operator from PowerShell 7.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$($tags ? \"-tag $($tags -join ',')\" : $null)<\/code><\/pre>\n\n\n\n<p>If you want to use my function in Windows PowerShell, you'll need to revise it.<\/p>\n\n\n\n<p>The function writes strings to the pipeline.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"398\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock-1024x398.png\" alt=\"New-PesterBlock\" class=\"wp-image-8756\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock-1024x398.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock-300x117.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock-768x298.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock-1536x596.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock-850x330.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/new-pesterblock.png 1733w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>I can run New-PesterBlock and pipe to Out-File or Set-Clipboard.<\/p>\n\n\n\n<p>Here's the script file with the function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">#requires -version 7.1\n\nFunction New-PesterBlock {\n    &lt;#\n.SYNOPSIS\n    Create a Pester 5.x test block\n.DESCRIPTION\n    Create a Pester test block for exported functions from a given module.\n    The default output is a Describe block for each function but you can\n    create a Context block as an alternative.\n\n    The default behavior is to add a 'Function' tag to each block. You\n    can specify your own comma separated list of tags. Or use a parameter\n    value of $Null to not insert any tags.\n\n    The output is written for Pester 5.x.\n.EXAMPLE\n    PS C:\\> New-PesterBlock psteachingtools\n\n    Describe Get-Vegetable {\n    It \"Should have help documentation\" {\n        (Get-Help Get-Vegetable).Description | Should -Not -BeNullOrEmpty\n    }\n    It \"Should have a defined output type\" {\n        (Get-Command -CommandType function -name Get-Vegetable).OutputType | Should -not -BeNullOrEmpty\n    }\n    It \"Should run without error\" {\n        #mock and set mandator parameters as needed\n        {Get-Vegetable} | Should -Not -Throw\n    } -pending\n\n} -tag function\n\nDescribe New-Vegetable {\n    It \"Should have help documentation\" {\n        (Get-Help New-Vegetable).Description | Should -Not -BeNullOrEmpty\n    }\n    It \"Should have a defined output type\" {\n        (Get-Command -CommandType function -name New-Vegetable).OutputType | Should -not -BeNullOrEmpty\n    }\n    It \"Should run without error\" {\n        #mock and set mandator parameters as needed\n        {New-Vegetable} | Should -Not -Throw\n    } -pending\n\n} -tag function\n...\n\n        Create a Describe block for each function in the PSTeachingTools module.\n. EXAMPLE\n    PS C:\\> New-Pesterblock psteachingtools -BlockType Context | Set-Clipboard\n\n    Create a context block for each function and copy the output to the Windows clipboard.\n.INPUTS\n    None\n.OUTPUTS\n    [System.String]\n    #>\n    [cmdletbinding()]\n    [alias(\"npb\")]\n    [OutputType([System.String])]\n    Param(\n        [Parameter(Position = 0, Mandatory,HelpMessage = \"The name of a PowerShell module.\")]\n        [ValidateNotNullOrEmpty()]\n        [string]$ModuleName,\n        [Parameter(Position = 1,HelpMessage = \"What kind of Pester test block do you want to create?\")]\n        [ValidateSet(\"Describe\", \"Context\")]\n        [string]$BlockType = \"Describe\",\n        [Parameter(HelpMessage = \"Specify tags separated by commas. Use `$null to not insert any tags.\")]\n        [string[]]$Tag = \"function\"\n    )\n    Begin {\n        Write-Verbose \"[$((Get-Date).TimeofDay) BEGIN  ] Starting $($myinvocation.mycommand)\"\n        #Put blocktype in proper case to make it pretty\n        $BlockType = [System.Globalization.CultureInfo]::CurrentUICulture.TextInfo.ToTitleCase($BlockType)\n        $Tags = $tag -join \",\"\n    } #begin\n\n    Process {\n        Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Getting commands from $ModuleName\"\n        Try {\n            $cmds = Get-Command -Module $ModuleName -CommandType Function -ErrorAction Stop\n        }\n        Catch {\n            Throw $_\n        }\n        if ($cmds) {\n            Foreach ($cmd in $cmds) {\n                Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Defining tests for $($cmd.name)\"\n                @\"\n\n$BlockType $($cmd.name) {\n    It \"Should have help documentation\" {\n        (Get-Help $($cmd.name)).Description | Should -Not -BeNullOrEmpty\n    }\n    It \"Should have a defined output type\" {\n        (Get-Command -CommandType function -name $($cmd.name)).OutputType | Should -Not -BeNullOrEmpty\n    }\n    It \"Should run without error\" {\n        &lt;#\n        mock and set mandatory parameters as needed\n        this test is marked as pending since it\n        most likely needs to be refined\n        #>\n        {$($cmd.name)} | Should -Not -Throw\n    } -pending\n    #insert additional command-specific tests\n\n} $($tags ? \"-tag $($tags -join ',')\" : $null)\n\"@\n            } #foreach cmd\n\n        } #if cmds\n        else {\n            Write-Warning \"No functions found in the module $Modulename or the module itself doesn't exist.\"\n        }\n    } #process\n\n    End {\n        Write-Verbose \"[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)\"\n    } #end\n\n} #close New-PesterBlock\n<\/code><\/pre>\n\n\n\n<p>The function creates a here-string for each test block. These are my default assertions. You might want to edit your version of the function. This command is something I might integrate into a VS Code task. I hope you'll let me know how you end up using it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day I shared my PowerShell plans for 2022. And needless to say, I didn&#8217;t wait to dig in. I am working on a new module and since it won&#8217;t be published until next month, I went ahead and marked it as Core only. I also started writing a set of Pester 5.x tests&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New on the blog: Accelerating Pester Test Development with this #PowerShell function","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,610,8],"tags":[224,520,534],"class_list":["post-8754","post","type-post","status-publish","format-standard","hentry","category-powershell","category-powershell-7","category-scripting","tag-function","tag-pester","tag-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Accelerate Pester Test Development &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"Pester tests in PowerShell are a great idea but can be tedious to write. Here&#039;s a PowerShell function I use to speed up the process.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Accelerate Pester Test Development &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Pester tests in PowerShell are a great idea but can be tedious to write. Here&#039;s a PowerShell function I use to speed up the process.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-28T16:41:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-28T16:41:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/pexels-thisisengineering-3862132.jpg\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Accelerate Pester Test Development\",\"datePublished\":\"2021-12-28T16:41:50+00:00\",\"dateModified\":\"2021-12-28T16:41:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/\"},\"wordCount\":337,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/pexels-thisisengineering-3862132.jpg\",\"keywords\":[\"Function\",\"Pester\",\"PowerShell\"],\"articleSection\":[\"PowerShell\",\"PowerShell 7\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/\",\"name\":\"Accelerate Pester Test Development &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/pexels-thisisengineering-3862132.jpg\",\"datePublished\":\"2021-12-28T16:41:50+00:00\",\"dateModified\":\"2021-12-28T16:41:53+00:00\",\"description\":\"Pester tests in PowerShell are a great idea but can be tedious to write. Here's a PowerShell function I use to speed up the process.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/pexels-thisisengineering-3862132.jpg\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/pexels-thisisengineering-3862132.jpg\",\"width\":320,\"height\":213},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8754\\\/accelerate-pester-test-development\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Accelerate Pester Test Development\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Accelerate Pester Test Development &#8226; The Lonely Administrator","description":"Pester tests in PowerShell are a great idea but can be tedious to write. Here's a PowerShell function I use to speed up the process.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/","og_locale":"en_US","og_type":"article","og_title":"Accelerate Pester Test Development &#8226; The Lonely Administrator","og_description":"Pester tests in PowerShell are a great idea but can be tedious to write. Here's a PowerShell function I use to speed up the process.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/","og_site_name":"The Lonely Administrator","article_published_time":"2021-12-28T16:41:50+00:00","article_modified_time":"2021-12-28T16:41:53+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/pexels-thisisengineering-3862132.jpg","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Accelerate Pester Test Development","datePublished":"2021-12-28T16:41:50+00:00","dateModified":"2021-12-28T16:41:53+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/"},"wordCount":337,"commentCount":3,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/pexels-thisisengineering-3862132.jpg","keywords":["Function","Pester","PowerShell"],"articleSection":["PowerShell","PowerShell 7","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/","name":"Accelerate Pester Test Development &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/pexels-thisisengineering-3862132.jpg","datePublished":"2021-12-28T16:41:50+00:00","dateModified":"2021-12-28T16:41:53+00:00","description":"Pester tests in PowerShell are a great idea but can be tedious to write. Here's a PowerShell function I use to speed up the process.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/pexels-thisisengineering-3862132.jpg","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/pexels-thisisengineering-3862132.jpg","width":320,"height":213},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8754\/accelerate-pester-test-development\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Accelerate Pester Test Development"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":8766,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8766\/discovering-pester-tags-revisited\/","url_meta":{"origin":8754,"position":0},"title":"Discovering Pester Tags Revisited","author":"Jeffery Hicks","date":"January 6, 2022","format":false,"excerpt":"Yesterday I shared some PowerShell code I wrote to discover tags in a Pester test. It works nicely and I have no reason to complain. But as usual, there is never simply one way to do something in PowerShell. I got a suggestion from @FrodeFlaten on Twitter on an approach\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/container-tags.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":8750,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8750\/powershell-plans-for-2022\/","url_meta":{"origin":8754,"position":1},"title":"PowerShell Plans for 2022","author":"Jeffery Hicks","date":"December 27, 2021","format":false,"excerpt":"I'm not much for writing year in review pieces. Nor, to be honest, do I often write New Year's resolutions. But I've been thinking about the work I've done this past year and what I might be doing in 2022 so I thought I'd share some thoughts on what 2022\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"binoculars","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/07\/pexels-skitterphoto-63901.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":8759,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8759\/discovering-pester-tags-with-the-powershell-ast\/","url_meta":{"origin":8754,"position":2},"title":"Discovering Pester Tags with the PowerShell AST","author":"Jeffery Hicks","date":"January 5, 2022","format":false,"excerpt":"As I resolved at the end of last year, I am doing more with Pester in 2022. I'm getting a bit more comfortable with Pester 5 and as my tests grow in complexity I am embracing the use of tags. You can add tags to different Pester test elements. Then\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/get-all-tag-values.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/get-all-tag-values.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/get-all-tag-values.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/01\/get-all-tag-values.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":4994,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4994\/creating-new-powershell-projects\/","url_meta":{"origin":8754,"position":3},"title":"Creating New PowerShell Projects","author":"Jeffery Hicks","date":"May 17, 2016","format":false,"excerpt":"I've been writing scripts since the early days of DOS batch files. Like many of you I simply stick them all in a folder and move on to the next project. Most of my work is just for me or writing projects so this methodology worked just fine for me.\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb.png?resize=525%2C300 1.5x"},"classes":[]},{"id":9023,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9023\/powershell-first-timers\/","url_meta":{"origin":8754,"position":4},"title":"PowerShell First-Timers","author":"Jeffery Hicks","date":"May 11, 2022","format":false,"excerpt":"Are you a PowerShell first-timer? Someone who is finally dipping their toes into the PowerShell pool. Or maybe you want to poke around and see what all the fuss is about. If so, here are some steps you might want to take. Even if you've been using PowerShell for a\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/05\/pester-install-fail.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/05\/pester-install-fail.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/05\/pester-install-fail.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/05\/pester-install-fail.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":7409,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7409\/importing-pester-results-into-powershell\/","url_meta":{"origin":8754,"position":5},"title":"Importing Pester Results into PowerShell","author":"Jeffery Hicks","date":"April 24, 2020","format":false,"excerpt":"Last week, a PowerShell scripting challenge was posted on the Iron Scripter web site.\u00a0 The idea was that when you run a Pester test, you can save the results to a specially formatted\u00a0 XML file. Invoke-Pester C:\\scripts\\sample.test.ps1 -OutputFile d:\\temp\\results.xml -OutputFormat JUnitXml I get this result. The challenge was to write\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/informationvariable-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/informationvariable-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/informationvariable-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/informationvariable-1.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/informationvariable-1.png?resize=1050%2C600&ssl=1 3x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8754","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=8754"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8754\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}