When you are developing Powershell scripts, creating some unit tests will help you in monitoring the quality of the scripts. Writing some tests will give you some assurance that your code still works after you make some changes. Writing Powershell unit tests can be done with Pester. Pester will enable you to test your Powershell scripts from within Powershell. It is a set of Powershell functions for unit testing Powershell. These functions will allow you to mock and isolate the Powershell code under test. When you want to integrate your unit test into your VSTS build pipeline, you need an build extension to run then in your build pipeline.
Adam Bertram @adbertram
It’s Monday. Run those PSPester tests for your #PowerShell code before getting started. You never know how you left that code on Friday!
Run tests in VSTS
When you want to run your Pester unit test in your VSTS build pipeline, you need to add the Pester task from the marketplace into your VSTS project. Then open the build pipeline and Add the Pester task.
The following configuration will run all Pester unit tests in your project:
Test files : **/*.tests.ps1 Fail build on error : true
Upload the tests result
When you want the test results visible in VSTS, you need to upload the test result file. This can be done with the Upload test results task. Pester will write the test results in nUnit format to a test results file. This test results file is located in the test results directory of build agent. That is one directory higher than the working directory of the task.
Test Result Format : NUnit Test Results Files : ../**/TEST-*.xml Always run : true