-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (86 loc) · 3.25 KB
/
Copy pathunittest-verification.yml
File metadata and controls
102 lines (86 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: UnitTest-Verification
on:
workflow_dispatch:
pull_request:
branches:
- main
- develop
jobs:
build-and-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 10.x
- name: Restore dependencies
run: dotnet restore ./WebExpress.WebCore.sln
- name: Build project
run: dotnet build ./WebExpress.WebCore.sln --no-restore --configuration Release
- name: Run xUnit tests
id: tests
continue-on-error: true
run: dotnet test ./WebExpress.WebCore.Test/WebExpress.WebCore.Test.csproj --no-build --configuration Release -- --report-trx --results-directory ./TestResults
- name: Print failing tests on failure
if: steps.tests.outcome == 'failure'
shell: bash
run: |
python3 - <<'PY'
import glob
import sys
import xml.etree.ElementTree as ET
ns = '{http://microsoft.com/schemas/VisualStudio/TeamTest/2010}'
files = sorted(glob.glob('./TestResults/**/*.trx', recursive=True))
if not files:
print('No TRX report produced - cannot extract failure details.')
sys.exit(0)
total_failed = 0
for path in files:
print(f'::group::Report {path}')
try:
root = ET.parse(path).getroot()
except ET.ParseError as exc:
print(f'Failed to parse {path}: {exc}')
print('::endgroup::')
continue
report_failed = 0
for result in root.iter(f'{ns}UnitTestResult'):
if result.get('outcome') != 'Failed':
continue
report_failed += 1
total_failed += 1
print(f'\n--- FAILED: {result.get("testName")} ---')
err = result.find(f'.//{ns}ErrorInfo')
if err is not None:
message = err.find(f'{ns}Message')
stack = err.find(f'{ns}StackTrace')
if message is not None and message.text:
print('Message:')
print(message.text.rstrip())
if stack is not None and stack.text:
print('StackTrace:')
print(stack.text.rstrip())
stdout = result.find(f'.//{ns}Output/{ns}StdOut')
if stdout is not None and stdout.text:
print('StdOut:')
print(stdout.text.rstrip())
if report_failed == 0:
print('(no failed tests in this report)')
print('::endgroup::')
print(f'\nTotal failed tests: {total_failed}')
PY
- name: Upload TRX report
if: always()
uses: actions/upload-artifact@v4
with:
name: trx-results
path: src/TestResults/**/*.trx
if-no-files-found: ignore
- name: Fail workflow when tests failed
if: steps.tests.outcome == 'failure'
run: exit 1