On TestCases... #1997
Replies: 3 comments 9 replies
-
The lazy variables may reference other variables available at runtime than those in testcase, so we'd have to run all BeforeAll/BeforeEach setups as well which can be time-consuming. SkipRun currently skips the entire Run-phase to avoid that.
Testcases can be an array that's reused in multiple tests, even with similar or the same name. Wouldn't that make it unclear which test you're referencing? I do see you problem though as discussed earlier. It's hard to reference data-driven tests based due to script parameters and x levels of foreach/testcases. Best option is likely containerId:startline:testcaseindex (containerId being scritblock-id or path) and hope it's not so dynamic it changes on the next run. 😁 |
Beta Was this translation helpful? Give feedback.
-
It turns out that when doing discovery with NoRun, the Data property is populated! So it is possible to distinguish testcases. I made a function to generate unique test IDs even for TestCase Items. Lots of edge case issues but its good enough for now. Function function New-TestItemId {
<#
.SYNOPSIS
Create a string that uniquely identifies a test or test suite
.NOTES
Can be replaced with expandedpath if https://github.com/pester/Pester/issues/2005 is fixed
#>
[CmdletBinding()]
param(
[Parameter(Mandatory,ValueFromPipeline)]
[ValidateScript({
$null -ne ($_.PSTypeNames -match '^(Pester\.)?Test$')
})]$Test
)
process {
if ($Test.Path -match '\|') {
throw [NotSupportedException]"The pipe character '|' is not supported in test names with this adapter. Please remove all pipes from test/context/describe names"
}
#TODO: Edge cases
#Non-String Object
#Non-STring Hashtable
#Other dictionaries
#Nested Hashtables
#Fancy TestCases, maybe just iterate them as TestCaseN or exclude
$Data = $Test.Data
if ($Data) {
if ($Data -is [IDictionary]) {
$Test.Data.GetEnumerator() | Sort-Object Name | Foreach-Object {
$Test.Path += [String]([String]$PSItem.Name + '=' + [String]$PSItem.Value)
}
} else {
$Test.Path += [string]$Data
}
}
$Test.Path -join '|'
}
} Result on several tests including testcases. ➜ (invoke-pester -Configuration @{Run=@{SkipRun=$true;PassThru=$true}}).tests | New-TestItemId
|
Beta Was this translation helpful? Give feedback.
-
Implemented in JustinGrote/_PR-vscode-pester-test-adapter@3e6f6b9 And I am able to correlate the tests together using my constructed id. |
Beta Was this translation helpful? Give feedback.
-
I noticed that testcases return multiple results in both NoRun and Run mode.
Two questions:
Example:
Translated JSON Output by PesterInterface.ps1
Beta Was this translation helpful? Give feedback.
All reactions