0

I want to create a test with Pester. I have to create some files and then read them with a filter.

The problem I get is when I use $PSScriptRoot. If I run the test in the Windows PowerShell ISE, it is working.

enter image description here

The same test in a PowerShell using

Invoke-Pester -Output Detailed .\MyTest.Tests.ps1

returns an error:

ParameterBindingValidationException: Cannot bind argument to parameter 'Path' because it is null.

The $path is defined $targetPath = $PSScriptRoot. I tried to use $psISE like in this post with the same result. Also I noticed that $psISE returns the path of Pester and not the local path (in the screenshot below C:\Program Files\WindowsPowerShell\Modules\Pester\5.4.1).

enter image description here

How can I fix the script to run it with Windows PowerShell ISE, PowerShell and also in an Azure pipeline?

Enrico
  • 3,592
  • 6
  • 45
  • 102
  • 1
    Its difficult to assist without you providing some code we can use to reproduce the problem. However if your use of $PSScriptRoot is just to set a folder for creating/modifying/deleting test files, consider using TestDrive:\ (also available as $TestDrive) instead: https://pester.dev/docs/usage/testdrive – Mark Wragg May 10 '23 at 16:21
  • Variables set in the `BeforeDiscovery` fase are defined in another scope than the `BeforeAll` step. Make sure you set `$targetPath = $PSScriptRoot` within the `BeforeAll` scope – mhu Jun 05 '23 at 16:14

0 Answers0