- August 19, 2016 at 5:59 am #51070
I am having my .ps1 saved in directory1 and mt .tests.ps1 in directory2 with in the same folder.
In general we use to write the script as follows when the test file and script file are in the same folder
$here = Split-Path -Parent $MyInvocation.MyCommand.Path $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' . "$here\$sut"
But I am having them in different folder, so how can I load the path so that the script file should get loadedAugust 19, 2016 at 7:47 am #51091
Example of a solution for your question:
$here = Split-Path -Parent $MyInvocation.MyCommand.Path $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace('.Tests.ps1','.ps1') . "$(Join-Path -Path $here -ChildPath "..\Pester\$sut" -Resolve)"
August 19, 2016 at 8:14 am #51094
- This reply was modified 1 month, 1 week ago by Daniel Krebs.
Getting the following error
Join-Path : Cannot find path 'D:\PowerShell\Pester\TestPester\Pester\PowerShellTest1.tests.ps1' because it does not exist.
At D:\PowerShell\Pester\TestPester\MyProject.Tests\PowerShellTest1.tests.ps1:3 char:6August 19, 2016 at 8:30 am #51098
I'm sure you can find out yourself. The code is not really complex. Most likely the folder layout is different from what you've posted earlier or you've removed the .. in my example.
-DanielAugust 19, 2016 at 8:34 am #51100
I have written as per you posted, My .ps1 is in A folder and my test script in B folder, I believe the code you have given is searching in current directory B instead of AAugust 19, 2016 at 12:54 pm #51147
I have achieved as follows
$project = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace(".Tests", "") $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".tests.", ".") . "$project\$sut"
You must be logged in to reply to this topic.