How do I investigate a test failure?
For the conventions tests follow (file structure, naming, helpers), see Unit test conventions. To enable logging, see How do I enable test logging?.
Question
A unit test is failing. How do I find the root cause from the results XML and the per-test logs?
Answer
- Scope the investigation. Ask the user which suite(s) and
whether they want one specific failure or all failures in the
suite. Typical suites:
ores.accounts.tests,ores.refdata.tests,ores.cli.tests, or theratmeta-target that runs everything. Enable logging. Off by default for performance. Per How do I enable test logging?:
cmake --preset linux-clang-debug-ninja -DORES_TEST_LOG_LEVEL=debug # or for more detail cmake --preset linux-clang-debug-ninja \ -DORES_TEST_LOG_LEVEL=trace -DORES_TEST_LOG_CONSOLE=ON
Run the failing suite. Run only what you need to keep noise down:
cmake --build --target test_ores.accounts.tests \ --preset linux-clang-debug-ninjaReplace
ores.accountswith the target component. Use--target ratto run everything.Parse the results. The script reads the test-result XML files alongside their log files and prints a per-suite summary with failure locations and the relevant log lines:
./scripts/parse_test_results.py \ build/output/linux-clang-debug-ninja/publish/binOutput sections:
- File summary — which XMLs were found and where logs live.
- Per-suite results — per failed test: exception message,
test line, duration, links to the per-test log, and
any
[ERROR]/[WARN]lines in the log. - Overall summary — total / pass / fail counts and rates.
- Walk the investigation in this order:
- Read the Exception line — the assertion or thrown error.
- Open the test file at the reported
file:lineto see what the test expected. - Read the per-test log (under
build/output/<preset>/publish/log/<suite>/<category>/<test>.log) for[ERROR]/[WARN]entries. - If the per-test log is not enough, read the suite-level log one folder up.
- Crank the log level to
traceand re-run (step 2 + 3). - As a last resort, add targeted
BOOST_LOG_SEV(lg, debug) <<lines into the code under test, rebuild, re-run.
- Common surprises:
- "No test logs found" → logging is disabled; go back to step 2.
- XML parse error → the test binary crashed before writing a clean result XML; the script dumps the full suite log so you can find the crash site.
Disable logging when done, to keep the test suite quick:
cmake --preset linux-clang-debug-ninja -DORES_TEST_LOG_LEVEL=OFF
Script
scripts/parse_test_results.py does the XML + log parsing and
report layout.
Tested by
Manual. The script is exercised every time tests go red.
See also
- How do I enable test logging? — the prerequisite knob.
- How do I run the tests? — the surrounding run loop.
- Unit test conventions — what to read in the test file once you find it.
- code-investigate-test-failure skill — the skill that drives this recipe.