Summary
This chapter explored the complex topic of testing in PowerShell.
Static analysis is one part of testing and is the approach used by modules like PSScriptAnalyzer
. Static analysis makes use of the AST and tokenizers in PowerShell.
The AST describes the content of a block of code as a tree of different elements, starting with a ScriptBlockAst
at the highest level. The ParseInput
and ParseFile
methods of the Parser
type can be used to get either an instance of the AST for a piece of code or the tokens that make up a script that includes comments.
The ShowPSAst
module can be used to visualize and explore the AST tree. ShowPSAst
is a useful tool when starting to work with AST as the tree can quickly become complex.
PSScriptAnalyzer
uses either the AST or tokens to define rules. Rules can be used to test and enforce personal or organization-specific practices.
Pester is a testing framework and this chapter explores both acceptance and unit testing.
Acceptance...