Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
July 9, 2024

More Pester Testing .NET with Copilot

Last time I started exploring how to build a set of Pester tests for code that is written around the .NET Framework. I am using the `Get-OSDetail` function that uses raw .NET classes for CIM objects. In the previous article, I shared the process I used to build the Pester test with the assistance of GitHub CoPilot in VS Code. If you read the last article, you know that the AI-generated code is far from perfect. You still have to know how to write a Pester test. But Copilot did accelerate the process and in many cases provided a good starting point. ## Organizing the Pester Tests When we left off, I had a test that would validate the function's design and input. When Copilot created a test for the `CimSession` parameter, it kindly organized the test in a `Context` block. I often like to organize my tests in this way. It makes it easier to understand the purpose of the test and to run tests selectively.

Pester Context
figure 1
I added an outer `Context` block for each parameter even though I only have one. If I add more parameters, I can define additional `Context` blocks for each. This also serves as a template for future tests.
Get a premium subscription for full article and archive access

Last time, I started exploring how to build a set of Pester tests for code written around the .NET Framework. I am using the Get-OSDetail function that uses raw .NET classes for CIM objects. In the previous article, I shared the process I used to build the Pester test with the assistance of GitHub CoPilot in VS Code. If you read the last article, you know the AI-generated code is far from perfect. You still have to understand how to write a Pester test. However, Copilot accelerated the process and provided a good starting point in many cases.

Organizing the Pester Tests

When we left off, I had a test that would validate the function's design and input. When Copilot created a test for the CimSession parameter, it kindly organized the test in a Context block. I often like to organize my tests in this way. It makes it easier to understand the test's purpose and selectively run tests.

Want to read the full issue?
GitHub Bluesky LinkedIn About Jeff
Powered by Buttondown, the easiest way to start and grow your newsletter.