"""Aggregate JUnit XML results from multiple test runs."""
import xml.etree.ElementTree as ET
from pathlib import Path
from dataclasses import dataclass
from typing import List
@dataclass
class TestRunSummary:
suite_name: str
timestamp: str
total: int
passed: int
failed: int
errors: int
duration_s: float
@property
def pass_rate(self) -> float:
return self.passed / max(self.total, 1) * 100
def aggregate_xml_reports(report_dir: str) -> List[TestRunSummary]:
summaries = []
for xml_file in Path(report_dir).glob("*.xml"):
tree = ET.parse(xml_file)
suite = tree.getroot()
if suite.tag != "testsuite":
suite = suite.find("testsuite") or suite
total = int(suite.get("tests", 0))
failed = int(suite.get("failures", 0))
errors = int(suite.get("errors", 0))
passed = total - failed - errors
summaries.append(TestRunSummary(
suite_name=suite.get("name", xml_file.stem),
timestamp =suite.get("timestamp", ""),
total=total, passed=passed,
failed=failed, errors=errors,
duration_s=float(suite.get("time", 0))
))
return summariesTest Result Aggregation from JUnit XML
Flaky Test Detection
"""Detect flaky tests by analysing historical results."""
from collections import defaultdict
from typing import List, Dict
def detect_flaky_tests(
run_history: List[Dict[str, str]],
min_runs: int = 5,
flaky_threshold_pct: float = 20.0) -> list:
"""A test is flaky if it fails in 5-95% of runs."""
test_results = defaultdict(list)
for run in run_history:
for tc_id, verdict in run.items():
test_results[tc_id].append(verdict)
flaky = []
for tc_id, verdicts in test_results.items():
if len(verdicts) < min_runs:
continue
fail_rate = verdicts.count("FAIL") / len(verdicts) * 100
if flaky_threshold_pct <= fail_rate <= (100 - flaky_threshold_pct):
flaky.append({
"tc_id": tc_id,
"fail_rate_pct": round(fail_rate, 1),
"runs": len(verdicts)
})
return sorted(flaky, key=lambda x: -x["fail_rate_pct"])Summary
Test result dashboards serve a different purpose than individual test reports: they answer questions about test suite health over time rather than individual test outcomes. The three most important metrics are: pass rate trend (is the test suite becoming more or less stable?), flaky test count (how many tests produce inconsistent results, indicating timing issues or test isolation problems?), and test execution duration trend (is the test suite growing faster than the CI/CD time budget?). A flaky test in automotive testing is particularly dangerous because it erodes trust in the test suite: if engineers learn to ignore intermittent failures, they also ignore real failures hidden among the noise.
🔬 Deep Dive — Core Concepts Expanded
This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.
Key principles to reinforce:
- Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
- Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
- Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.
🏭 How This Topic Appears in Production Projects
- Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
- Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
- Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.
⚠️ Common Mistakes and How to Avoid Them
- Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
- Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
- Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
- Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.
📊 Industry Note
Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.