Closed tbergstedt closed 3 years ago
You are defining $changedItems
in BeforeAll
and use it for -ForEach, but BeforeAll executes after ForEach so the variable is not defined.
Thank you for the quick reply. I understand why it went wrong, but I'm afraid I also need some guidance on how to use -ForEach
with Pester 5 syntax. If I'm not to define the variable in BeforeAll
, but before theIt
statement, where should I define it?
Use BeforeDiscovery
to gather data to use with -Foreach
. See https://pester.dev/docs/usage/data-driven-tests#beforediscovery
Thanks for the quick help!
General summary of the issue
We have been using Pester v4 as a verification and validation engine within Azure DevOps Server 2020, where we execute scripts with Pester functionality to produce test results. So it isn't validation of Powershell functionality per se. When trying to run these tests using Pester v5, they seemingly wont execute at all, and the only output is an exception (see below).
Describe your environment
Pester version : 5.1.1 C:\Users\tober\Documents\PowerShell\Modules\pester\5.1.1\Pester.psm1 PowerShell version : 7.1.2 OS version : Microsoft Windows NT 10.0.18363.0
Steps to reproduce
A typical validation script is formed like this (post v5 conversion):
-->
Expected Behavior
Pester execution of the
BeforeAll
clause should setup test behavior and retrieve items to test. TheIt
clause should be executed for each file in $changedItemsCurrent Behavior
None of the Pester blocks are ever executed, but seems to simply be skipped. Execution ends with the output
Comment
Is execution/usage of Pester much more strict with version 5? We aren't testing any Powershell script per se, but this was fine in version 4. And I fail to see any errors in the v5 structure above. I have tried moving the
-ForEach
statement up to theDescribe
level, to no avail.