Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TestCategory and MachineName to JUnitReport #3416

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LISAv2-Framework.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function Start-LISAv2 {
}
}

if (($failedCount -eq 0 -and $errorCount -eq 0 -and $testCount -gt 0) -or (-not $RunInParallel -and $TestIdInParallel)) {
if (($failedCount -eq 0 -and $errorCount -eq 0 -and $testCount -ge 0) -or (-not $RunInParallel -and $TestIdInParallel)) {
$ExitCode = 0
} else {
$ExitCode = 1
Expand Down
12 changes: 10 additions & 2 deletions Libraries/TestReport.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,18 @@ Class JUnitReportGenerator
[System.Xml.XmlElement] $ReportRootNode
[object] $TestSuiteLogTable
[object] $TestSuiteCaseLogTable

JUnitReportGenerator([string]$ReportPath)
[string] $TestCategory
[string] $MachineName
JUnitReportGenerator([string]$ReportPath,[string]$TestCategory,[string]$MachineName)
{
$this.JunitReportPath = $ReportPath
$this.JunitReport = New-Object System.Xml.XmlDocument
$newElement = $this.JunitReport.CreateElement("testsuites")
$this.ReportRootNode = $this.JunitReport.AppendChild($newElement)
$this.TestSuiteLogTable = @{}
$this.TestSuiteCaseLogTable = @{}
$this.TestCategory=$TestCategory
$this.MachineName=$MachineName
}

[void] SaveLogReport()
Expand All @@ -156,6 +159,11 @@ Class JUnitReportGenerator
$newElement.SetAttribute("errors", 0)
$newElement.SetAttribute("skipped", 0)
$newElement.SetAttribute("time", 0)
$newElement.SetAttribute("TestCategory", $this.TestCategory)
$newElement.SetAttribute("MachineName", $this.MachineName)
if ( $global:BaseOSVHD ) {
$newElement.SetAttribute("ImageUnderTest", $global:BaseOSVHD )
}
$testsuiteNode = $this.ReportRootNode.AppendChild($newElement)

$testsuite = [ReportNode]::New($testsuiteNode)
Expand Down
30 changes: 19 additions & 11 deletions TestControllers/TestController.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Class TestController {
[string] $RGIdentifier
[string] $OsVHD
[string] $TestCategory
[string] $MachineName
[string] $TestNames
[string] $TestArea
[string] $TestTag
Expand Down Expand Up @@ -270,6 +271,7 @@ Class TestController {
$this.SetupTypeToTestCases = @{}
$this.SetupTypeTable = @{}
$allTests = $null
$this.MachineName=""
$SetupTypeXMLs = Get-ChildItem -Path "$WorkingDirectory\XML\VMConfigurations\*.xml"
foreach ($file in $SetupTypeXMLs.FullName) {
$setupXml = [xml]( Get-Content -Path $file)
Expand Down Expand Up @@ -302,11 +304,16 @@ Class TestController {
foreach ($CustomParameter in $CustomTestParameters) {
$ReplaceThis = $CustomParameter.Split("=")[0]
$ReplaceWith = $CustomParameter.Substring($CustomParameter.IndexOf("=") + 1)
$OldValue = ($ReplaceableTestParameters.ReplaceableTestParameters.Parameter | Where-Object `
{ $_.ReplaceThis -eq $ReplaceThis }).ReplaceWith
($ReplaceableTestParameters.ReplaceableTestParameters.Parameter | Where-Object `
{ $_.ReplaceThis -eq $ReplaceThis }).ReplaceWith = $ReplaceWith
Write-LogInfo "Custom Parameter: $ReplaceThis=$OldValue --> $ReplaceWith"
if($ReplaceThis -eq "MachineName") {
$this.MachineName=$ReplaceWith
}
else {
$OldValue = ($ReplaceableTestParameters.ReplaceableTestParameters.Parameter | Where-Object `
{ $_.ReplaceThis -eq $ReplaceThis }).ReplaceWith
($ReplaceableTestParameters.ReplaceableTestParameters.Parameter | Where-Object `
{ $_.ReplaceThis -eq $ReplaceThis }).ReplaceWith = $ReplaceWith
Write-LogInfo "Custom Parameter: $ReplaceThis=$OldValue --> $ReplaceWith"
}
}
Write-LogInfo "Custom parameter(s) are ready to be injected along with default parameters, if any."
}
Expand All @@ -323,12 +330,13 @@ Class TestController {
}
}
if (!$allTests) {
Throw "Not able to collect any test cases from XML files"
}
else {
$collectedTCCount = $allTests.Count
Write-LogInfo "$collectedTCCount Test Cases have been collected"
Write-LogWarn "Not able to collect any test cases from XML files"
LiliDeng marked this conversation as resolved.
Show resolved Hide resolved
return
}

$collectedTCCount = $allTests.Count
Write-LogInfo "$collectedTCCount Test Cases have been collected"

$this.PrepareSetupTypeToTestCases($this.SetupTypeToTestCases, $allTests)
if (($this.TotalCaseNum -eq 0) -or ($allTests.Count -eq 0)) {
Write-LogWarn "All collected test cases are skipped, because the test case has native SetupConfig that conflicts with current Run-LISAv2 parameters, or LISAv2 needs more specific parameters to run against selected test cases, please check again"
Expand Down Expand Up @@ -903,7 +911,7 @@ Class TestController {

Write-LogInfo "Prepare test log structure and start testing now ..."
# Start JUnit XML report logger.
$this.JunitReport = [JUnitReportGenerator]::New($TestReportXmlPath)
$this.JunitReport = [JUnitReportGenerator]::New($TestReportXmlPath,$this.TestCategory,$this.MachineName)
$this.JunitReport.StartLogTestSuite("LISAv2Test-$($this.TestPlatform)")
$this.TestSummary = [TestSummary]::New($this.TestCategory, $this.TestArea, $this.TestNames, $this.TestTag, $this.TestPriority, $this.TotalCaseNum)

Expand Down