SlideShare a Scribd company logo
1
How to
Test PowerShell Code
Using Pester
2
Chris Wahl
Writer
Co-Host
Instructor
Technologist
Author
Microsoft
VMware
@ WahlNetwork.com
@ DatanautsPodcast.com
@ Pluralsight.com
@ Rubrik.com
Networking for VMware Admins
MVP (PowerShell)
VCDX #104 (DCV & NV)
Get-Person
3
5
Pester … what?
6
Drivers for Change
• You want to test your scripts for bugs
– But you feel bad making other humans do this for you
• You freely admit and acknowledge that testing isn’t
possible with your own meat spatulas
• You also like to automate stuff to avoid more work
7
How Pester Helps
• You write one or more unit tests
• Pester executes them
• The tests either pass or fail
• Results are displayed
8
Example 1
Given an input of $false
You expect a return of $false
9
10
What Happened?
• The function was evaluated
• The return value was $true
• Pester uses the “Should Be” to compare against $false
• These values don’t match
• The test fails
Let’s Dig Deeper into Pester
The Describe Block
• This is your logical grouping of tests
• It’s also a testing scope
– You can define “mock” commands within this scope
• Child objects:
– Context = a group of “it” tests
– It = a single test
13
The Context Block
• A way to logically divide your Describe blocks
• Ex: Run tests under one context / account, then repeat
using a different one
• Ex: Test using a “user” account and then again using a
“super user” or “admin” account
• Ex: Start with a relative path and then a strict path
14
The It Block
• This is where you run a specific test
• One set of inputs, one set of outputs
• Don’t get all fancy pants
• Use the Arrange-Act-Assert format
– Get data
– Test it
– Make sure it ran (code coverage)
15
Describe, Context, and It
• Describe … a group of API specific tests
– Context … a group of tests against an old API version
• It … runs tests against function1
• It … runs tests against function2
• It … runs tests against function3
– Context … a group of tests against a new API version
• It … (repeat tests from before)
• Describe … a group of parameter tests
• And so on …
16
Example 2
Using “Should” in a variety of ways
17
18
Example 3
What if you can’t use the real code?
19
20
Example 4
Leveraging Pester with other build systems
21
• Many systems can leverage Pester tests
• AppVeyor is a popular CI / build system
– https://ci.appveyor.com/project/brianbunke/confluenceps
– http://wahlnetwork.com/2017/04/18/version-and-publish-
powershell-appveyor/
23
Closing Remarks and Resources
24
Thoughts
• Keep your functions as small as possible
– I prefer one logical statement per function
• Unit test the functions rather than the workflows
• Embrace TDD and creating tests for everything you do
• As you encounter an issue, build a test for it
– That way it never happens again
– Crush tribal knowledge!
• Be kind to your future self
25
26
Resources
• Pester
– https://github.com/pester/Pester
• The Pester Book
– https://leanpub.com/pesterbook
• PowerShell Summit “Lightning Demos”
– https://github.com/RamblingCookieMonster/CommunityLightning
Demos2017
• xUnit Test Patterns: Refactoring Test Code
– http://amzn.to/2pcaKQK
PowerShell / Pester Twitter Folks
27
Chris Hunt
Twitter: @logicaldiagram
Adam Bertram
Twitter: @adbertram
Jeffrey Snover
Twitter: @jsnover

More Related Content

What's hot

Continuous integration of_puppet_code
Continuous integration of_puppet_codeContinuous integration of_puppet_code
Continuous integration of_puppet_code
Devoteam Revolve
 
Load Testing with JMeter, BlazeMeter, New Relic
Load Testing with JMeter, BlazeMeter, New RelicLoad Testing with JMeter, BlazeMeter, New Relic
Load Testing with JMeter, BlazeMeter, New Relic
Giedrius Krisciukaitis, PMP
 
Twin Cities Code Camp - DevOps In Action
Twin Cities Code Camp - DevOps In ActionTwin Cities Code Camp - DevOps In Action
Twin Cities Code Camp - DevOps In Action
David Strebel
 
Kloud
KloudKloud
WinOps Conf 2015 - Microsoft Azure & Open Source
WinOps Conf 2015 - Microsoft Azure & Open SourceWinOps Conf 2015 - Microsoft Azure & Open Source
WinOps Conf 2015 - Microsoft Azure & Open Source
WinOps Conf
 
What DevOps Isn't
What DevOps Isn'tWhat DevOps Isn't
What DevOps Isn't
Frank Lamantia
 
[Christopher Ngo] Intro DevOPS XP Day 2015
[Christopher Ngo] Intro DevOPS XP Day 2015[Christopher Ngo] Intro DevOPS XP Day 2015
[Christopher Ngo] Intro DevOPS XP Day 2015
Agile đây Vietnam
 
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentationLONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
Sriram Angajala
 
DevOps In Action
DevOps In ActionDevOps In Action
DevOps In Action
David Strebel
 
Cloud Needs Devops
Cloud Needs DevopsCloud Needs Devops
Cloud Needs Devops
Kris Buytaert
 
Don't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen EmeryDon't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen Emery
DevOpsDays Baltimore
 
Michigan IT Symposium 2017 - CI/CD Workflow Tutorial
Michigan IT Symposium 2017 - CI/CD Workflow TutorialMichigan IT Symposium 2017 - CI/CD Workflow Tutorial
Michigan IT Symposium 2017 - CI/CD Workflow Tutorial
Jeffrey Sica
 
Installation Guide - Octopus
Installation Guide - OctopusInstallation Guide - Octopus
Installation Guide - Octopus
vincent.biot
 
Jenkins tutorial for beginners
Jenkins tutorial for beginnersJenkins tutorial for beginners
Jenkins tutorial for beginners
BugRaptors
 
Jenkins Overview
Jenkins OverviewJenkins Overview
Jenkins Overview
Ahmed M. Gomaa
 
Performance Tuning in the Trenches
Performance Tuning in the TrenchesPerformance Tuning in the Trenches
Performance Tuning in the Trenches
Donald Belcham
 
Drupal Continuous Integration with Jenkins - Deploy
Drupal Continuous Integration with Jenkins - DeployDrupal Continuous Integration with Jenkins - Deploy
Drupal Continuous Integration with Jenkins - Deploy
John Smith
 
Genomics data insights
Genomics data insightsGenomics data insights
Genomics data insights
Vishwas N
 
An Introduction To Jenkins
An Introduction To JenkinsAn Introduction To Jenkins
An Introduction To Jenkins
Knoldus Inc.
 
Continuous delivery applied (RJUG)
Continuous delivery applied (RJUG)Continuous delivery applied (RJUG)
Continuous delivery applied (RJUG)
Mike McGarr
 

What's hot (20)

Continuous integration of_puppet_code
Continuous integration of_puppet_codeContinuous integration of_puppet_code
Continuous integration of_puppet_code
 
Load Testing with JMeter, BlazeMeter, New Relic
Load Testing with JMeter, BlazeMeter, New RelicLoad Testing with JMeter, BlazeMeter, New Relic
Load Testing with JMeter, BlazeMeter, New Relic
 
Twin Cities Code Camp - DevOps In Action
Twin Cities Code Camp - DevOps In ActionTwin Cities Code Camp - DevOps In Action
Twin Cities Code Camp - DevOps In Action
 
Kloud
KloudKloud
Kloud
 
WinOps Conf 2015 - Microsoft Azure & Open Source
WinOps Conf 2015 - Microsoft Azure & Open SourceWinOps Conf 2015 - Microsoft Azure & Open Source
WinOps Conf 2015 - Microsoft Azure & Open Source
 
What DevOps Isn't
What DevOps Isn'tWhat DevOps Isn't
What DevOps Isn't
 
[Christopher Ngo] Intro DevOPS XP Day 2015
[Christopher Ngo] Intro DevOPS XP Day 2015[Christopher Ngo] Intro DevOPS XP Day 2015
[Christopher Ngo] Intro DevOPS XP Day 2015
 
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentationLONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
 
DevOps In Action
DevOps In ActionDevOps In Action
DevOps In Action
 
Cloud Needs Devops
Cloud Needs DevopsCloud Needs Devops
Cloud Needs Devops
 
Don't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen EmeryDon't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen Emery
 
Michigan IT Symposium 2017 - CI/CD Workflow Tutorial
Michigan IT Symposium 2017 - CI/CD Workflow TutorialMichigan IT Symposium 2017 - CI/CD Workflow Tutorial
Michigan IT Symposium 2017 - CI/CD Workflow Tutorial
 
Installation Guide - Octopus
Installation Guide - OctopusInstallation Guide - Octopus
Installation Guide - Octopus
 
Jenkins tutorial for beginners
Jenkins tutorial for beginnersJenkins tutorial for beginners
Jenkins tutorial for beginners
 
Jenkins Overview
Jenkins OverviewJenkins Overview
Jenkins Overview
 
Performance Tuning in the Trenches
Performance Tuning in the TrenchesPerformance Tuning in the Trenches
Performance Tuning in the Trenches
 
Drupal Continuous Integration with Jenkins - Deploy
Drupal Continuous Integration with Jenkins - DeployDrupal Continuous Integration with Jenkins - Deploy
Drupal Continuous Integration with Jenkins - Deploy
 
Genomics data insights
Genomics data insightsGenomics data insights
Genomics data insights
 
An Introduction To Jenkins
An Introduction To JenkinsAn Introduction To Jenkins
An Introduction To Jenkins
 
Continuous delivery applied (RJUG)
Continuous delivery applied (RJUG)Continuous delivery applied (RJUG)
Continuous delivery applied (RJUG)
 

Similar to How to Test PowerShell Code Using Pester

Automation for Anyone at Nutanix NEXT 2017 US
Automation for Anyone at Nutanix NEXT 2017 USAutomation for Anyone at Nutanix NEXT 2017 US
Automation for Anyone at Nutanix NEXT 2017 US
Chris Wahl
 
Mastering PowerShell Testing with Pester
Mastering PowerShell Testing with PesterMastering PowerShell Testing with Pester
Mastering PowerShell Testing with Pester
Mark Wragg
 
Lecture #6. automation testing (andrey oleynik)
Lecture #6. automation testing (andrey oleynik)Lecture #6. automation testing (andrey oleynik)
Lecture #6. automation testing (andrey oleynik)
Andrey Oleynik
 
Software testing ... who’s responsible is it?
Software testing ... who’s responsible is it?Software testing ... who’s responsible is it?
Software testing ... who’s responsible is it?
Manjula03809891
 
Software testing ... who is responsible for it?
Software testing ... who is responsible for it?Software testing ... who is responsible for it?
Software testing ... who is responsible for it?
Manjula Piyumal
 
Write tests, please
Write tests, pleaseWrite tests, please
Write tests, please
Joan López de la Franca
 
Unit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUGUnit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUG
egoodwintx
 
Software Testing
Software TestingSoftware Testing
Software Testing
AdroitLogic
 
JAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & JasmineJAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & Jasmine
Anup Singh
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
wajrcs
 
Unit Testing in Swift
Unit Testing in SwiftUnit Testing in Swift
Unit Testing in Swift
GlobalLogic Ukraine
 
Addressing Security Regression Through Unit Testing
Addressing Security Regression Through Unit TestingAddressing Security Regression Through Unit Testing
Addressing Security Regression Through Unit Testing
Christopher Grayson
 
Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platform
Chamil Madusanka
 
Static Code Analysis: Keeping the Cost of Bug Fixing Down
Static Code Analysis:  Keeping the Cost of Bug Fixing DownStatic Code Analysis:  Keeping the Cost of Bug Fixing Down
Static Code Analysis: Keeping the Cost of Bug Fixing Down
Andrey Karpov
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Sergey Podolsky
 
Functional Tests. PHP Unconf 2016
Functional Tests. PHP Unconf 2016Functional Tests. PHP Unconf 2016
Functional Tests. PHP Unconf 2016
Vladislav Fedorischev
 
A Software Testing Intro
A Software Testing IntroA Software Testing Intro
A Software Testing Intro
Evozon Test Lab
 
No Devops Without Continuous Testing
No Devops Without Continuous TestingNo Devops Without Continuous Testing
No Devops Without Continuous Testing
Parasoft
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sergey Aganezov
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspec
jeffrey1ross
 

Similar to How to Test PowerShell Code Using Pester (20)

Automation for Anyone at Nutanix NEXT 2017 US
Automation for Anyone at Nutanix NEXT 2017 USAutomation for Anyone at Nutanix NEXT 2017 US
Automation for Anyone at Nutanix NEXT 2017 US
 
Mastering PowerShell Testing with Pester
Mastering PowerShell Testing with PesterMastering PowerShell Testing with Pester
Mastering PowerShell Testing with Pester
 
Lecture #6. automation testing (andrey oleynik)
Lecture #6. automation testing (andrey oleynik)Lecture #6. automation testing (andrey oleynik)
Lecture #6. automation testing (andrey oleynik)
 
Software testing ... who’s responsible is it?
Software testing ... who’s responsible is it?Software testing ... who’s responsible is it?
Software testing ... who’s responsible is it?
 
Software testing ... who is responsible for it?
Software testing ... who is responsible for it?Software testing ... who is responsible for it?
Software testing ... who is responsible for it?
 
Write tests, please
Write tests, pleaseWrite tests, please
Write tests, please
 
Unit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUGUnit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUG
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
JAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & JasmineJAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & Jasmine
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
 
Unit Testing in Swift
Unit Testing in SwiftUnit Testing in Swift
Unit Testing in Swift
 
Addressing Security Regression Through Unit Testing
Addressing Security Regression Through Unit TestingAddressing Security Regression Through Unit Testing
Addressing Security Regression Through Unit Testing
 
Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platform
 
Static Code Analysis: Keeping the Cost of Bug Fixing Down
Static Code Analysis:  Keeping the Cost of Bug Fixing DownStatic Code Analysis:  Keeping the Cost of Bug Fixing Down
Static Code Analysis: Keeping the Cost of Bug Fixing Down
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Functional Tests. PHP Unconf 2016
Functional Tests. PHP Unconf 2016Functional Tests. PHP Unconf 2016
Functional Tests. PHP Unconf 2016
 
A Software Testing Intro
A Software Testing IntroA Software Testing Intro
A Software Testing Intro
 
No Devops Without Continuous Testing
No Devops Without Continuous TestingNo Devops Without Continuous Testing
No Devops Without Continuous Testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspec
 

More from Chris Wahl

Scotland VMUG - My Journey to Full Stack Engineering
Scotland VMUG - My Journey to Full Stack EngineeringScotland VMUG - My Journey to Full Stack Engineering
Scotland VMUG - My Journey to Full Stack Engineering
Chris Wahl
 
Norway VMUG Tour - The Architecture Behind Policy-Driven Data Protection - A ...
Norway VMUG Tour - The Architecture Behind Policy-Driven Data Protection - A ...Norway VMUG Tour - The Architecture Behind Policy-Driven Data Protection - A ...
Norway VMUG Tour - The Architecture Behind Policy-Driven Data Protection - A ...
Chris Wahl
 
VMUG - My Journey to Full Stack Engineering
VMUG - My Journey to Full Stack EngineeringVMUG - My Journey to Full Stack Engineering
VMUG - My Journey to Full Stack Engineering
Chris Wahl
 
VMUG - Learning to Learn - Experiences and Tips for Certifications and Tech S...
VMUG - Learning to Learn - Experiences and Tips for Certifications and Tech S...VMUG - Learning to Learn - Experiences and Tips for Certifications and Tech S...
VMUG - Learning to Learn - Experiences and Tips for Certifications and Tech S...
Chris Wahl
 
VMUG - Mastering PowerShell to Call RESTful API Endpoints
VMUG - Mastering PowerShell to Call RESTful API EndpointsVMUG - Mastering PowerShell to Call RESTful API Endpoints
VMUG - Mastering PowerShell to Call RESTful API Endpoints
Chris Wahl
 
VMworld - vSphere Distributed Switch 6.0 Technical Deep Dive
VMworld - vSphere Distributed Switch 6.0 Technical Deep DiveVMworld - vSphere Distributed Switch 6.0 Technical Deep Dive
VMworld - vSphere Distributed Switch 6.0 Technical Deep Dive
Chris Wahl
 
VMUG - Using PowerShell to call RESTful APIs
VMUG - Using PowerShell to call RESTful APIsVMUG - Using PowerShell to call RESTful APIs
VMUG - Using PowerShell to call RESTful APIs
Chris Wahl
 
VMUG - Community - Two Sides of the Same Coin
VMUG - Community - Two Sides of the Same CoinVMUG - Community - Two Sides of the Same Coin
VMUG - Community - Two Sides of the Same Coin
Chris Wahl
 
VMUG - Picking Up New Skills - Tips and Tricks to Build Your Technical Tool C...
VMUG - Picking Up New Skills - Tips and Tricks to Build Your Technical Tool C...VMUG - Picking Up New Skills - Tips and Tricks to Build Your Technical Tool C...
VMUG - Picking Up New Skills - Tips and Tricks to Build Your Technical Tool C...
Chris Wahl
 
vBrownBag - Scripting and Versioning with PowerShell ISE and Git Shell
vBrownBag - Scripting and Versioning with PowerShell ISE and Git ShellvBrownBag - Scripting and Versioning with PowerShell ISE and Git Shell
vBrownBag - Scripting and Versioning with PowerShell ISE and Git Shell
Chris Wahl
 
A No-Nonsense Approach to Hyperconvergence
A No-Nonsense Approach to HyperconvergenceA No-Nonsense Approach to Hyperconvergence
A No-Nonsense Approach to Hyperconvergence
Chris Wahl
 
VMUG St Louis - SDN in the Real World
VMUG St Louis - SDN in the Real WorldVMUG St Louis - SDN in the Real World
VMUG St Louis - SDN in the Real World
Chris Wahl
 

More from Chris Wahl (12)

Scotland VMUG - My Journey to Full Stack Engineering
Scotland VMUG - My Journey to Full Stack EngineeringScotland VMUG - My Journey to Full Stack Engineering
Scotland VMUG - My Journey to Full Stack Engineering
 
Norway VMUG Tour - The Architecture Behind Policy-Driven Data Protection - A ...
Norway VMUG Tour - The Architecture Behind Policy-Driven Data Protection - A ...Norway VMUG Tour - The Architecture Behind Policy-Driven Data Protection - A ...
Norway VMUG Tour - The Architecture Behind Policy-Driven Data Protection - A ...
 
VMUG - My Journey to Full Stack Engineering
VMUG - My Journey to Full Stack EngineeringVMUG - My Journey to Full Stack Engineering
VMUG - My Journey to Full Stack Engineering
 
VMUG - Learning to Learn - Experiences and Tips for Certifications and Tech S...
VMUG - Learning to Learn - Experiences and Tips for Certifications and Tech S...VMUG - Learning to Learn - Experiences and Tips for Certifications and Tech S...
VMUG - Learning to Learn - Experiences and Tips for Certifications and Tech S...
 
VMUG - Mastering PowerShell to Call RESTful API Endpoints
VMUG - Mastering PowerShell to Call RESTful API EndpointsVMUG - Mastering PowerShell to Call RESTful API Endpoints
VMUG - Mastering PowerShell to Call RESTful API Endpoints
 
VMworld - vSphere Distributed Switch 6.0 Technical Deep Dive
VMworld - vSphere Distributed Switch 6.0 Technical Deep DiveVMworld - vSphere Distributed Switch 6.0 Technical Deep Dive
VMworld - vSphere Distributed Switch 6.0 Technical Deep Dive
 
VMUG - Using PowerShell to call RESTful APIs
VMUG - Using PowerShell to call RESTful APIsVMUG - Using PowerShell to call RESTful APIs
VMUG - Using PowerShell to call RESTful APIs
 
VMUG - Community - Two Sides of the Same Coin
VMUG - Community - Two Sides of the Same CoinVMUG - Community - Two Sides of the Same Coin
VMUG - Community - Two Sides of the Same Coin
 
VMUG - Picking Up New Skills - Tips and Tricks to Build Your Technical Tool C...
VMUG - Picking Up New Skills - Tips and Tricks to Build Your Technical Tool C...VMUG - Picking Up New Skills - Tips and Tricks to Build Your Technical Tool C...
VMUG - Picking Up New Skills - Tips and Tricks to Build Your Technical Tool C...
 
vBrownBag - Scripting and Versioning with PowerShell ISE and Git Shell
vBrownBag - Scripting and Versioning with PowerShell ISE and Git ShellvBrownBag - Scripting and Versioning with PowerShell ISE and Git Shell
vBrownBag - Scripting and Versioning with PowerShell ISE and Git Shell
 
A No-Nonsense Approach to Hyperconvergence
A No-Nonsense Approach to HyperconvergenceA No-Nonsense Approach to Hyperconvergence
A No-Nonsense Approach to Hyperconvergence
 
VMUG St Louis - SDN in the Real World
VMUG St Louis - SDN in the Real WorldVMUG St Louis - SDN in the Real World
VMUG St Louis - SDN in the Real World
 

Recently uploaded

OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 

Recently uploaded (20)

OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 

How to Test PowerShell Code Using Pester

  • 1. 1 How to Test PowerShell Code Using Pester
  • 2. 2 Chris Wahl Writer Co-Host Instructor Technologist Author Microsoft VMware @ WahlNetwork.com @ DatanautsPodcast.com @ Pluralsight.com @ Rubrik.com Networking for VMware Admins MVP (PowerShell) VCDX #104 (DCV & NV) Get-Person
  • 3. 3
  • 4.
  • 6. 6 Drivers for Change • You want to test your scripts for bugs – But you feel bad making other humans do this for you • You freely admit and acknowledge that testing isn’t possible with your own meat spatulas • You also like to automate stuff to avoid more work
  • 7. 7 How Pester Helps • You write one or more unit tests • Pester executes them • The tests either pass or fail • Results are displayed
  • 8. 8 Example 1 Given an input of $false You expect a return of $false
  • 9. 9
  • 10. 10 What Happened? • The function was evaluated • The return value was $true • Pester uses the “Should Be” to compare against $false • These values don’t match • The test fails
  • 11. Let’s Dig Deeper into Pester
  • 12. The Describe Block • This is your logical grouping of tests • It’s also a testing scope – You can define “mock” commands within this scope • Child objects: – Context = a group of “it” tests – It = a single test
  • 13. 13 The Context Block • A way to logically divide your Describe blocks • Ex: Run tests under one context / account, then repeat using a different one • Ex: Test using a “user” account and then again using a “super user” or “admin” account • Ex: Start with a relative path and then a strict path
  • 14. 14 The It Block • This is where you run a specific test • One set of inputs, one set of outputs • Don’t get all fancy pants • Use the Arrange-Act-Assert format – Get data – Test it – Make sure it ran (code coverage)
  • 15. 15 Describe, Context, and It • Describe … a group of API specific tests – Context … a group of tests against an old API version • It … runs tests against function1 • It … runs tests against function2 • It … runs tests against function3 – Context … a group of tests against a new API version • It … (repeat tests from before) • Describe … a group of parameter tests • And so on …
  • 16. 16 Example 2 Using “Should” in a variety of ways
  • 17. 17
  • 18. 18 Example 3 What if you can’t use the real code?
  • 19. 19
  • 20. 20 Example 4 Leveraging Pester with other build systems
  • 21. 21 • Many systems can leverage Pester tests • AppVeyor is a popular CI / build system – https://ci.appveyor.com/project/brianbunke/confluenceps – http://wahlnetwork.com/2017/04/18/version-and-publish- powershell-appveyor/
  • 22.
  • 24. 24 Thoughts • Keep your functions as small as possible – I prefer one logical statement per function • Unit test the functions rather than the workflows • Embrace TDD and creating tests for everything you do • As you encounter an issue, build a test for it – That way it never happens again – Crush tribal knowledge! • Be kind to your future self
  • 25. 25
  • 26. 26 Resources • Pester – https://github.com/pester/Pester • The Pester Book – https://leanpub.com/pesterbook • PowerShell Summit “Lightning Demos” – https://github.com/RamblingCookieMonster/CommunityLightning Demos2017 • xUnit Test Patterns: Refactoring Test Code – http://amzn.to/2pcaKQK
  • 27. PowerShell / Pester Twitter Folks 27 Chris Hunt Twitter: @logicaldiagram Adam Bertram Twitter: @adbertram Jeffrey Snover Twitter: @jsnover