Automated Test Report Generation: A Practical Automotive Engineering Guide
Automated test reports convert execution data into reviewable engineering evidence. In automotive ECU testing, a useful report should explain what was tested, against which requirement, on which ECU/software baseline, under what bench conditions, and why a test passed or failed.
A robust design separates test execution, structured result storage, report generation and artifact retention. This makes the report reproducible and allows the same results to be rendered as HTML, PDF or a dashboard without rerunning the ECU test.
1. Report-generation architecture
Keep the original execution results as the source of truth. The report is a view of those results, not a replacement for them.
| Component | Responsibility |
|---|---|
| Test runner | Executes test cases and records observations |
| Result model | Stores test identity, metadata, measurements and verdict |
| Validator | Checks required fields, data types and allowed verdicts |
| Aggregator | Calculates totals and summarizes outcomes |
| Renderer | Produces HTML or another presentation format |
| Artifact store | Retains BLF, log, screenshot and other evidence files |
2. Define a stable result schema
Agree on a result structure before writing templates. A practical record can include:
| Field | Purpose |
|---|---|
run_id | Identifies one complete test execution |
test_id | Unique test-case identifier within the test catalog |
requirement_id | Requirement verified by the test |
status | PASS, FAIL, INCONCLUSIVE, SKIPPED or ERROR |
started_at, ended_at | Time-stamped execution boundaries with timezone |
ecu_sw | ECU software/build identification |
bench_id | Test bench or setup identification |
measurements | Observed values, units and limits |
artifacts | Relative paths to trace files and logs |
failure_reason | Explanation when the test does not pass |
Use a schema version so that future changes to the result format can be handled explicitly. Do not silently reinterpret old result files after changing field names or verdict rules.
3. Example structured test result
The following JSON record is illustrative:
{
"schema_version": "1.0",
"run_id": "RUN_2026_001",
"test_id": "NET_001",
"requirement_id": "REQ-COM-012",
"status": "PASS",
"started_at": "2026-11-28T09:00:00+05:30",
"ended_at": "2026-11-28T09:00:04+05:30",
"ecu_sw": "example-build-id",
"bench_id": "HIL_BENCH_01",
"measurements": [
{
"name": "message_inter_arrival",
"observed": 99.8,
"unit": "ms",
"limit_min": 90.0,
"limit_max": 110.0
}
],
"artifacts": [
"artifacts/RUN_2026_001/NET_001.blf"
],
"failure_reason": null
}
The example values are not acceptance criteria. Actual limits, timestamps, identifiers and software versions must come from the test execution and approved project requirements.
4. Generate an HTML report with Python
This example uses only the Python standard library. It reads structured JSON, validates essential fields, calculates a verdict summary and creates an HTML report. Dynamic text is escaped before insertion into HTML.
import json
from collections import Counter
from html import escape
from pathlib import Path
ALLOWED_STATUSES = {
"PASS", "FAIL", "INCONCLUSIVE", "SKIPPED", "ERROR"
}
def load_results(path: Path) -> list[dict]:
data = json.loads(path.read_text(encoding="utf-8"))
if not isinstance(data, list):
raise ValueError("Expected a JSON array of test results")
required = {"test_id", "requirement_id", "status"}
for index, record in enumerate(data):
if not isinstance(record, dict):
raise ValueError(f"Record {index} is not an object")
missing = required - record.keys()
if missing:
raise ValueError(
f"Record {index} is missing: {sorted(missing)}"
)
if record["status"] not in ALLOWED_STATUSES:
raise ValueError(
f"Unsupported status in record {index}: "
f"{record['status']}"
)
return data
def build_report(records: list[dict]) -> str:
counts = Counter(record["status"] for record in records)
rows = []
for record in records:
rows.append(
"<tr>"
f"<td>{escape(str(record['test_id']))}</td>"
f"<td>{escape(str(record['requirement_id']))}</td>"
f"<td>{escape(str(record['status']))}</td>"
f"<td>{escape(str(record.get('failure_reason') or ''))}</td>"
"</tr>"
)
summary = " | ".join(
f"{status}: {counts.get(status, 0)}"
for status in sorted(ALLOWED_STATUSES)
)
return f"""<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ECU Test Report</title>
<style>
body {{ font-family: Arial, sans-serif; margin: 2rem; }}
table {{ border-collapse: collapse; width: 100%; }}
th, td {{ border: 1px solid #ccc; padding: 0.6rem; text-align: left; }}
th {{ background: #eee; }}
</style>
</head>
<body>
<h1>ECU Test Report</h1>
<p>{escape(summary)}</p>
<table>
<thead><tr>
<th>Test ID</th><th>Requirement</th>
<th>Status</th><th>Failure reason</th>
</tr></thead>
<tbody>{''.join(rows)}</tbody>
</table>
</body>
</html>"""
if __name__ == "__main__":
input_file = Path("results.json")
output_file = Path("test-report.html")
results = load_results(input_file)
report_html = build_report(results)
output_file.write_text(report_html, encoding="utf-8")
print(f"Generated {output_file} for {len(results)} test records")
This is a compact reporting example, not a complete production framework. A production pipeline should also validate timestamp formats, measurement types and artifact references; record the generator version; and define behavior for empty, incomplete or interrupted runs.
5. Calculate meaningful test statistics
A report should show the count of every outcome, not just a pass percentage. Keep these categories visible:
- PASS: all defined acceptance checks passed.
- FAIL: observed ECU behavior violated an acceptance criterion.
- INCONCLUSIVE: available evidence is insufficient for a valid product verdict.
- SKIPPED: the test was intentionally not executed.
- ERROR: execution or infrastructure prevented a valid test result.
If a pass rate is displayed, define its denominator. For example, a project may calculate pass rate as PASS / (PASS + FAIL), while separately reporting skipped, inconclusive and error counts. Never silently remove non-pass outcomes from the summary.
6. Link traces and supporting artifacts safely
Automotive test evidence may include BLF traces, CAN logs, screenshots, diagnostic logs, measurement exports and test-runner output.
Recommended practices:
- Store large files separately from the HTML report.
- Link artifacts using controlled relative paths or an artifact-service identifier.
- Verify that each referenced file exists before publishing the report.
- Prevent path traversal when resolving user- or runner-supplied paths.
- Preserve original files and avoid modifying raw trace evidence during report generation.
- Record file size, checksum or immutable artifact ID when required by the project.
- Apply access controls and retention rules to logs that may contain sensitive vehicle or customer data.
Do not embed arbitrary file paths or raw log content directly into HTML. Escape displayed text and validate artifact destinations.
7. Handle incomplete and abnormal runs
Report generation must not hide partial execution. Consider these conditions:
| Condition | Recommended report behavior |
|---|---|
| Missing required field | Reject or quarantine the malformed record and report the validation error |
| Duplicate test record | Apply a documented uniqueness rule; do not silently overwrite |
| Test runner interrupted | Mark the run incomplete and preserve completed records |
| Missing trace file | Show the missing artifact explicitly |
| Unknown verdict | Flag schema/version incompatibility |
| Invalid timestamp or timezone | Report a data-quality error rather than guessing |
| Empty test run | Generate an explicit no-results or incomplete-run status |
| HTML rendering failure | Preserve source JSON and log the generation error |
A report should distinguish test execution failures from report-generation failures. A failed renderer must never turn an ECU test into a pass.
8. Verification matrix for the reporting pipeline
| Test area | Input or condition | Expected result |
|---|---|---|
| Valid data | Complete result records | Report contains all test records |
| Missing field | Required ID or status absent | Validation error is visible |
| Invalid verdict | Unsupported status value | Record is rejected or quarantined |
| HTML injection | Log text contains markup characters | Text is displayed safely, not executed |
| Duplicate IDs | Repeated test identity | Documented duplicate handling |
| Timezone | Timestamps with different offsets | Original offsets are preserved or normalized consistently |
| Artifact link | Referenced file does not exist | Missing artifact is flagged |
| Partial run | Runner stops before all tests finish | Run is marked incomplete |
| Large run | Many records and artifacts | Report remains usable and generation is measured |
| Repeatability | Same input and generator version | Equivalent report content is produced |
9. Common implementation mistakes
- Mixing execution and presentation: makes the test runner difficult to maintain.
- Keeping only the HTML: loses machine-readable source data needed for later analysis.
- Counting only completed tests: can hide errors, skipped tests and incomplete runs.
- Unescaped log content: can create HTML injection vulnerabilities.
- Broken artifact links: make the report poor evidence for debugging.
- Missing software/configuration metadata: prevents reliable comparison between runs.
- Guessing timezones: can make event ordering and latency analysis misleading.
- Overwriting previous reports: destroys traceability between test executions.
- Treating report creation as a test pass: report generation and ECU verdicts are separate outcomes.
10. Recommended implementation workflow
- Agree on a versioned result schema with the test automation team.
- Capture test metadata and verdicts directly from the runner.
- Preserve raw results as immutable JSON or another structured format.
- Validate required fields, types, timestamps and verdict values.
- Aggregate all outcomes with clearly defined statistics.
- Check and link the trace/log artifacts.
- Render HTML from escaped, validated data.
- Archive the input data, report, generator version and artifacts together.
- Test the report pipeline with malformed, partial and large result sets.
11. Engineering checklist
- Result schema is documented and versioned.
- Each test has a stable ID and requirement reference.
- ECU software, bench and configuration metadata are recorded.
- Verdict categories and pass-rate denominator are explicit.
- Raw machine-readable results are retained.
- Dynamic HTML content is escaped.
- Artifact references are validated and access-controlled.
- Timezone and incomplete-run behavior are defined.
- Report-generation errors are separate from ECU test verdicts.
- Reports can be reproduced from archived inputs and generator version.
12. Check your understanding
- Why should structured test results be stored separately from the HTML report?
- Why is it misleading to calculate pass rate while silently excluding skipped and error cases?
- What security risk is reduced by escaping test names and log excerpts before rendering HTML?
- Which metadata is needed to compare test results from two ECU software builds?
- How should a report represent a test run interrupted before completion?
