Skip to content

Commit 694215f

Browse files
committed
Update build.yml
1 parent 6bab98a commit 694215f

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

.github/workflows/build.yml

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
env:
99
SOLUTION_FILE: ValueMapper/ValueMapper.sln
1010
PROJECT_PATH: ValueMapper/ValueMapperCore/ValueMapper.csproj
11+
TEST_RESULTS_PATH: TestResults
1112

1213
jobs:
1314
build:
@@ -31,9 +32,49 @@ jobs:
3132
- name: "Run tests"
3233
shell: pwsh
3334
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+
}
3980
}

0 commit comments

Comments
 (0)