Skip to content

Commit 8969761

Browse files
CedNaruclaude
andcommitted
Add per-test console output + JUnit/HTML reports to export test runner
The minimal export runner only returned an exit code. Attach GdUnitConsoleTestReporter for per-test PASS/FAIL console output and point report_base_path at <exported-executable-dir>/reports so the default session hooks write results.xml (JUnit) + HTML reports into harness/tests/export/reports - the directory the CI workflow uploads as the gdunit_reports_* artifact. Verified locally: exported run prints per-test results, writes a JUnit XML report (tests=111, failures=0) and HTML report, and exits 0 with clean shutdown. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 143e167 commit 8969761

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

harness/tests/test_runner/ExportTestRunner.gd

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@ const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
1414
## Directory (res://) that holds the GdUnit test suites to execute.
1515
const TEST_DIRECTORY := "res://test"
1616

17-
var _total_failures := 0
18-
var _total_errors := 0
17+
## Console writer + reporter for per-test PASS/FAIL output (same as the CLI runner).
18+
var _console := GdUnitCSIMessageWriter.new()
19+
var _console_reporter: GdUnitConsoleTestReporter
20+
21+
22+
func _ready() -> void:
23+
super()
24+
_console_reporter = GdUnitConsoleTestReporter.new(_console, true)
25+
# Write JUnit XML + HTML reports (produced by the default session hooks) next
26+
# to the exported executable. CI uploads this directory:
27+
# harness/tests/export/reports (and *.app/**/reports on macOS).
28+
report_base_path = OS.get_executable_path().get_base_dir().path_join("reports")
29+
# Surface gdUnit messages (e.g. the "Open ... Report at: ..." line) on the console.
30+
GdUnitSignals.instance().gdunit_message.connect(func(message: String) -> void:
31+
_console.color(Color.CORNFLOWER_BLUE).println_message(message))
1932

2033

2134
## Discover the test suites and start the run. Called by the base runner state machine.
@@ -49,17 +62,21 @@ func quit(code: int) -> void:
4962
await super(code)
5063

5164

52-
## Tally failures/errors as each test case finishes, to derive the process exit code.
65+
## Drive the console reporter from the test session so per-test results are printed.
5366
func _on_gdunit_event(event: GdUnitEvent) -> void:
54-
if event.type() == GdUnitEvent.TESTCASE_AFTER:
55-
_total_failures += event.failed_count()
56-
_total_errors += event.error_count()
67+
match event.type():
68+
GdUnitEvent.SESSION_START:
69+
_console_reporter.test_session = _test_session
70+
GdUnitEvent.SESSION_CLOSE:
71+
_console_reporter.test_session = null
5772

5873

5974
## Map the aggregated result to a process exit code consumed by CI / Gradle.
6075
func get_exit_code() -> int:
61-
if _total_failures + _total_errors > 0:
62-
prints("GdUnit export run finished with %d failure(s) and %d error(s)." % [_total_failures, _total_errors])
76+
var failures := _console_reporter.total_failure_count()
77+
var errors := _console_reporter.total_error_count()
78+
if failures + errors > 0:
79+
prints("GdUnit export run finished with %d failure(s) and %d error(s)." % [failures, errors])
6380
return RETURN_ERROR
6481
prints("GdUnit export run finished: all tests passed.")
6582
return RETURN_SUCCESS

harness/tests/test_runner/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ The exported executable is launched headless with this script as the main loop:
5353

5454
Exit code: `0` = all tests passed, `100` = failures/errors (see
5555
`GdUnitTestSessionRunner` return codes).
56+
57+
## Output
58+
59+
- **Console**: per-test PASS/FAIL output via `GdUnitConsoleTestReporter`.
60+
- **Reports**: the default session hooks write a JUnit XML report (`results.xml`)
61+
and an HTML report into `<exported-executable-dir>/reports/report_<n>/`
62+
(i.e. `harness/tests/export/reports/...`). This is the directory the CI
63+
workflow uploads as the `gdunit_reports_*` artifact.

0 commit comments

Comments
 (0)