Invoke-pester When Powershell file test is in a Function seems to not locate any tests #2156
|
I have been reading and reading but just cannot pin point an answer to my issue or lack of knowledge. Issue Outline: Here is a cut back version of my test sample: Calling the invoke-pester $Container = New-PesterContainer -Path "C:\QE\Pester\PesterStart.Test.ps1"
$Configuration = New-PesterConfiguration
$Configuration.Run.Container = $Container
$Configuration.TestResult.Enabled= $true
$Configuration.TestResult.OutputFormat = "NUnitXML"
$Configuration.TestResult.OutputPath = "Test-Pester.XML"
$Configuration.Output.Verbosity = "Detailed"
Invoke-Pester -Configuration $Configuration=========== function Set-location
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$False)][String]$NewCodes
)
BeforeAll{
Import-Module "C:\QE\Pester\Location.ps1" -Force
}
Describe 'Get urlLocation' {
Context 'urlLocation Creation' {
It "Auction Was set to east" {
Set-location -Location "east" | Should -Be "east"
}
}
}
}This will run but I get the following: Now if I change PesterStart.Test.ps1 file to: BeforeAll {
Import-Module "C:\Users\266542\OneDrive - CarMax\QE\Pester\Location.ps1" -Force
}
Describe 'Get urlLocation' {
Context 'urlLocation Creation' {
It "Auction Was set to east" {
Set-location -Location "east" | Should -Be "east"
}
}
}My output is Any ideas :) |
Replies: 3 comments 1 reply
|
I have worked around my issue, I just remove the function from the first script that contained the tests. Just had make some changes in azure to support how that script/function was being called. It still would be good to know why invoke-pester cannot call a script which has its tests in a function |
|
Calling the functions pesterstart.tests.ps1 to start the tests does not have issue. Its just that the script that is passed into invoke-pester cannot have a powershell function. I removed the function and just used params to get the data into the test script |
|
Pester runs the file to find the tests, your file only defines a function, it never calls it, so A test file can have functions in it, you just need the |
Pester runs the file to find the tests, your file only defines a function, it never calls it, so
Describenever runs and discovery finds nothing.A test file can have functions in it, you just need the
Describeblocks to run when the file is invoked. Either move them out of the function, or call the function at the end of the file.