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?

2
  • 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: pester.dev/docs/usage/testdrive Commented May 10, 2023 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 Commented Jun 5, 2023 at 16:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.