ecu-tests/docs/06_requirement_traceability.md

61 lines
1.4 KiB
Markdown

# Requirement Traceability
This document shows how requirements map to tests via pytest markers and docstrings, plus how to visualize coverage.
## Conventions
- Requirement IDs: `REQ-xxx`
- Use markers in tests: `@pytest.mark.req_001`, `@pytest.mark.req_002`, etc.
- Include readable requirement list in the test docstring under `Requirements:`
## Example
```python
@pytest.mark.req_001
@pytest.mark.req_003
"""
Title: Mock LIN Interface - Send/Receive Echo Test
Requirements: REQ-001, REQ-003
"""
```
## Mermaid: Requirement → Tests map
Note: This is illustrative; maintain it as your suite grows.
```mermaid
flowchart LR
R1[REQ-001: LIN Basic Ops]
R2[REQ-002: Master Request/Response]
R3[REQ-003: Frame Validation]
R4[REQ-004: Timeout Handling]
T1[test_mock_send_receive_echo]
T2[test_mock_request_synthesized_response]
T3[test_mock_receive_timeout_behavior]
T4[test_mock_frame_validation_boundaries]
R1 --> T1
R3 --> T1
R2 --> T2
R4 --> T3
R1 --> T4
R3 --> T4
```
## Generating a live coverage artifact (optional)
You can extend `conftest_plugin.py` to emit a JSON file with requirement-to-test mapping at the end of a run by scanning markers and docstrings. This can fuel dashboards or CI gates.
Suggested JSON shape:
```json
{
"requirements": {
"REQ-001": ["tests/test_smoke_mock.py::TestMockLinInterface::test_mock_send_receive_echo", "..."]
},
"uncovered": ["REQ-010", "REQ-012"]
}
```