Pester Testing .NET with Copilot
Pester Testing .NET with Copilot
Over the last few weeks, I've been showing how to build PowerShell tools that rely on the .NET Framework instead of calling native PowerShell commands like Get-CimInstance
. While you can see performance gains with this approach, there are potential drawbacks. First, your code could be a little more difficult to maintain by others. Native commands are at least easy to understand as long as you use full cmdlet and parameter names. Using the .NET Framework can make your code more arcane, especially for someone with less .NET experience than you. Internal documentation is critical if you take the approach I have been demonstrating.
Another area where you can encounter challenges is with Pester tests. You can only write tests for functions and cmdlets. And within those tests, you can only mock a command. You can't mock invoking a .NET method. I thought it would be helpful to write a Pester test for one of my recent functions. Then I realized I could also demonstrate how you might use GitHub Copilot in VS Code to help you write such a test.
I'll write a test for this function.