diff --git a/Actions/AnalyzeTests/TestResultAnalyzer.ps1 b/Actions/AnalyzeTests/TestResultAnalyzer.ps1 index 1beae6e4fa..7237072f97 100644 --- a/Actions/AnalyzeTests/TestResultAnalyzer.ps1 +++ b/Actions/AnalyzeTests/TestResultAnalyzer.ps1 @@ -295,9 +295,14 @@ function GetBcptSummaryMD { ) $bcpt = ReadBcptFile -bcptTestResultsFile $bcptTestResultsFile - if (-not $bcpt) { + if ($null -eq $bcpt) { return '' } + if ($bcpt.Count -eq 0) { + # File exists but contained no log entries - test run produced no output + OutputWarning "BCPT tests were run but produced no results. The BCPT test suite may have failed to start or the test codeunits exited without recording any measurements." + return "No BCPT results were recorded. The BCPT test suite may have failed to start or the test codeunits exited without recording any measurements.`n`n> Verify that the BCPT suite definition matches the published test codeunit IDs and that the test codeunits are reachable from the test runner." + } $baseLine = ReadBcptFile -bcptTestResultsFile $baseLinePath if ($baseLine) { if ($null -eq $bcptThresholds) { diff --git a/Tests/AnalyzeTests.Test.ps1 b/Tests/AnalyzeTests.Test.ps1 index b911958e9a..f53005c5f6 100644 --- a/Tests/AnalyzeTests.Test.ps1 +++ b/Tests/AnalyzeTests.Test.ps1 @@ -78,6 +78,38 @@ Describe "AnalyzeTests Action Tests" { $bcpt."SUITE1"."1".operations."operation2".measurements.Count | should -Be 4 } + It 'Test ReadBcptFile returns null when file does not exist' { + . (Join-Path $scriptRoot '../AL-Go-Helper.ps1') + . (Join-Path $scriptRoot 'TestResultAnalyzer.ps1') + $bcpt = ReadBcptFile -bcptTestResultsFile 'non-existent-file.json' + $bcpt | Should -Be $null + } + + It 'Test GetBcptSummaryMD returns empty string when file does not exist' { + . (Join-Path $scriptRoot '../AL-Go-Helper.ps1') + . (Join-Path $scriptRoot 'TestResultAnalyzer.ps1') + $md = GetBcptSummaryMD -bcptTestResultsFile 'non-existent-file.json' + $md | Should -Be '' + } + + It 'Test GetBcptSummaryMD returns warning message when file exists but contains no entries' { + . (Join-Path $scriptRoot '../AL-Go-Helper.ps1') + . (Join-Path $scriptRoot 'TestResultAnalyzer.ps1') + $emptyResultsFile = Join-Path ([System.IO.Path]::GetTempPath()) "$([GUID]::NewGuid().ToString()).json" + $script:warningCount = 0 + Mock OutputWarning { Param([string] $message) Write-Host "WARNING: $message"; $script:warningCount++ } + try { + Set-Content -Path $emptyResultsFile -Value '[]' -Encoding UTF8 + $md = GetBcptSummaryMD -bcptTestResultsFile $emptyResultsFile + $md | Should -Not -BeNullOrEmpty + $md | Should -Match 'No BCPT results were recorded' + $script:warningCount | Should -Be 1 + } + finally { + Remove-Item -Path $emptyResultsFile -Force -ErrorAction SilentlyContinue + } + } + It 'Test GetBcptSummaryMD (no baseline)' { . (Join-Path $scriptRoot '../AL-Go-Helper.ps1') . (Join-Path $scriptRoot 'TestResultAnalyzer.ps1')