@@ -1465,19 +1465,34 @@ function Invoke-DotNetTest {
14651465
14661466 Write-StepHeader " Running Tests with Coverage" - Tags " Invoke-DotNetTest"
14671467
1468+ # Check if there are any test projects in the solution
1469+ $testProjects = @ (Get-ChildItem - Recurse - Filter " *.csproj" | Where-Object {
1470+ $_.Name -match " \.Test\.csproj$" -or
1471+ $_.Directory.Name -match " \.Test$" -or
1472+ $_.Directory.Name -eq " Test" -or
1473+ (Select-String - Path $_.FullName - Pattern " <IsTestProject>true</IsTestProject>" - Quiet)
1474+ })
1475+
1476+ if ($testProjects.Count -eq 0 ) {
1477+ Write-Information " No test projects found in solution. Skipping test execution." - Tags " Invoke-DotNetTest"
1478+ return
1479+ }
1480+
1481+ Write-Information " Found $ ( $testProjects.Count ) test project(s)" - Tags " Invoke-DotNetTest"
1482+
14681483 # Ensure the TestResults directory exists
14691484 $testResultsPath = Join-Path $CoverageOutputPath " TestResults"
14701485 New-Item - Path $testResultsPath - ItemType Directory - Force | Out-Null
14711486
14721487 # Run tests with both coverage collection and TRX logging for SonarQube
1473- " dotnet test --configuration $Configuration /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput= `" coverage.opencover. xml`" --results-directory `" $testResultsPath `" --logger `" trx;LogFileName= TestResults.trx`" " | Invoke-ExpressionWithLogging | Write-InformationStream - Tags " Invoke-DotNetTest"
1488+ " dotnet test --configuration $Configuration --coverage --coverage-output-format xml --coverage-output `" coverage.xml`" --results-directory `" $testResultsPath `" --report-trx --report- trx-filename TestResults.trx" | Invoke-ExpressionWithLogging | Write-InformationStream - Tags " Invoke-DotNetTest"
14741489 Assert-LastExitCode " Tests failed"
14751490
14761491 # Find and copy coverage file to expected location for SonarQube
1477- $coverageFiles = @ (Get-ChildItem - Path . - Recurse - Filter " coverage.opencover. xml" - ErrorAction SilentlyContinue)
1492+ $coverageFiles = @ (Get-ChildItem - Path . - Recurse - Filter " coverage.xml" - ErrorAction SilentlyContinue)
14781493 if ($coverageFiles.Count -gt 0 ) {
14791494 $latestCoverageFile = $coverageFiles | Sort-Object LastWriteTime - Descending | Select-Object - First 1
1480- $targetCoverageFile = Join-Path $CoverageOutputPath " coverage.opencover. xml"
1495+ $targetCoverageFile = Join-Path $CoverageOutputPath " coverage.xml"
14811496 Copy-Item - Path $latestCoverageFile.FullName - Destination $targetCoverageFile - Force
14821497 Write-Information " Coverage file copied to: $targetCoverageFile " - Tags " Invoke-DotNetTest"
14831498 } else {
0 commit comments