|
8 | 8 | env: |
9 | 9 | SOLUTION_FILE: ValueMapper/ValueMapper.sln |
10 | 10 | PROJECT_PATH: ValueMapper/ValueMapperCore/ValueMapper.csproj |
| 11 | + TEST_RESULTS_PATH: TestResults |
11 | 12 |
|
12 | 13 | jobs: |
13 | 14 | build: |
|
31 | 32 | - name: "Run tests" |
32 | 33 | shell: pwsh |
33 | 34 | run: | |
34 | | - $testOutput = dotnet test ${{ env.SOLUTION_FILE }} --no-build --configuration Release --logger "console;verbosity=detailed" |
35 | | - if ($LASTEXITCODE -ne 0) { |
36 | | - Write-Output "::warning::Unit tests failed. Check the logs for details." |
37 | | - # This line ensures the step succeeds even though tests failed |
38 | | - exit 0 |
| 35 | + mkdir -p ${{ env.TEST_RESULTS_PATH }} |
| 36 | + dotnet test ${{ env.SOLUTION_FILE }} --no-build --configuration Release --logger "trx;LogFileName=test_results.trx" --results-directory ${{ env.TEST_RESULTS_PATH }} |
| 37 | + # Continue even if tests fail |
| 38 | + exit 0 |
| 39 | +
|
| 40 | + - name: "Upload test results" |
| 41 | + uses: actions/upload-artifact@v3 |
| 42 | + if: always() |
| 43 | + with: |
| 44 | + name: test-results |
| 45 | + path: ${{ env.TEST_RESULTS_PATH }} |
| 46 | + |
| 47 | + - name: "Test Report" |
| 48 | + uses: dorny/test-reporter@v1 |
| 49 | + if: always() |
| 50 | + with: |
| 51 | + name: .NET Tests |
| 52 | + path: "${{ env.TEST_RESULTS_PATH }}/*.trx" |
| 53 | + reporter: dotnet-trx |
| 54 | + fail-on-error: false |
| 55 | + |
| 56 | + - name: "Check for test failures" |
| 57 | + shell: pwsh |
| 58 | + if: always() |
| 59 | + run: | |
| 60 | + $trxFiles = Get-ChildItem -Path "${{ env.TEST_RESULTS_PATH }}" -Filter "*.trx" |
| 61 | + foreach ($file in $trxFiles) { |
| 62 | + $xml = [xml](Get-Content $file.FullName) |
| 63 | + $failedTests = $xml.SelectNodes("//UnitTestResult[@outcome='Failed']") |
| 64 | + $totalTests = $xml.SelectNodes("//UnitTestResult").Count |
| 65 | + $passedTests = $totalTests - $failedTests.Count |
| 66 | + |
| 67 | + Write-Output "Total Tests: $totalTests" |
| 68 | + Write-Output "Passed Tests: $passedTests" |
| 69 | + Write-Output "Failed Tests: $($failedTests.Count)" |
| 70 | + |
| 71 | + if ($failedTests.Count -gt 0) { |
| 72 | + Write-Output "::warning::❌ $($failedTests.Count) tests failed out of $totalTests tests" |
| 73 | + foreach ($test in $failedTests) { |
| 74 | + $testName = $test.testName |
| 75 | + Write-Output "::warning::Failed Test: $testName" |
| 76 | + } |
| 77 | + } else { |
| 78 | + Write-Output "::notice::✅ All $totalTests tests passed!" |
| 79 | + } |
39 | 80 | } |
0 commit comments