I am trying to unit test my Powershell script file with below code snippet using Pester
#code to create a 7z file
$7zipPath = "C:\Program Files\7-Zip\7z.exe"
Set-Alias 7zip $7zipPath
if (!(Test-Path -Path $7zipPath -PathType Leaf)) {
throw "7 zip file '$7zipPath' not found"
}
7zip a -mx=9 $jenkinsWorkspacepath\IntegrationZip.7z $jenkinsWorkspacepath\IntegratedScripts
And mocking the Test-Path command as below
Mock -CommandName Test-Path –MockWith {
Return $false
}
But the coverage report shows the below line as uncovered.. What am i doing wrong here(in the mocking part)?
**throw "7 zip file '$7zipPath' not found"**