@@ -20,17 +20,24 @@ Reference Docs in Tests
2020This guide explains how to annotate test cases so that
2121docs-as-code automatically creates traceability links between tests and requirements.
2222
23+ Details of implementation
24+ -------------------------
25+
2326The mechanism is language-agnostic:
24- Bazel produces JUnit-style ``test.xml `` files under ``bazel-testlogs/ ``.
25- The ``score_source_code_linker `` extension parses those files, extracts test metadata
27+ The ``score_source_code_linker `` extension parses ``test.xml `` files, extracts test metadata
2628(name, file, line, result, and verification properties),
2729and creates backlinks on the referenced requirements.
2830
31+ The extension will look for ``test.xml `` files in both ``bazel-testlogs/ ``
32+ as well as a folder named ``tests-report/ ``. This folder can be created manually if the tests
33+ require some pre-run step or are matrix tests or similar.
34+
35+
2936Required Properties
3037-------------------
3138
3239Every linked test must declare the following properties
33- (see :need: `gd_guidl__verification_specification `):
40+ (see :need: `gd_guidl__verification_specification ` for detailed values ):
3441
3542``PartiallyVerifies `` *and/or * ``FullyVerifies ``
3643 Comma-separated list of requirement IDs that the test covers.
@@ -43,8 +50,44 @@ Every linked test must declare the following properties
4350
4451``Description ``
4552 A human-readable explanation of the test objective and expected outcome.
46-
47- If any mandatory property is missing the test will be skipped during link creation.
53+ *In Python tests, a docstring takes the place of the description attribute. *
54+
55+ What should a test.xml look like?
56+ ---------------------------------
57+
58+ Each testcase has file as well as it's line number as additional attributes.
59+ Then as described above, each testcase also has properties inside the XML.
60+
61+ .. code-block :: xml
62+
63+ <?xml version =" 1.0" encoding =" utf-8" ?>
64+ <testsuites name =" pytest tests" >
65+ <testsuite errors =" 0" failures =" 0" hostname =" LG-0005" name =" pytest" skipped =" 0" tests =" 118" time =" 6.617" timestamp =" 2026-06-08T17:56:07.635773+00:00" >
66+ <testcase classname =" src.extensions.score_source_code_linker.tests.test_testlink" file =" src/extensions/score_source_code_linker/tests/test_testlink.py" line =" 40" name =" test_testlink_serialization_roundtrip" time =" 0.000" >
67+ <properties >
68+ <property name =" PartiallyVerifies" value =" tool_req__docs_test_link_testcase" ></property >
69+ <property name =" TestType" value =" requirements-based" ></property >
70+ <property name =" DerivationTechnique" value =" requirements-analysis" ></property >
71+ </properties >
72+ </testcase >
73+ <testcase classname =" src.extensions.score_source_code_linker.tests.test_testlink" file =" src/extensions/score_source_code_linker/tests/test_testlink.py" line =" 85" name =" test_clean_text_removes_ansi_and_html_unescapes" time =" 0.000" >
74+ <properties >
75+ <property name =" PartiallyVerifies" value =" tool_req__docs_test_link_testcase" ></property >
76+ <property name =" TestType" value =" requirements-based" ></property >
77+ <property name =" DerivationTechnique" value =" requirements-analysis" ></property >
78+ </properties >
79+ </testcase >
80+ </testsuite >
81+ </testsuites >
82+
83+ If you are not working in Python and using the provided pytest plugin, please ensure that the xml that is written in the end
84+ looks like this, otherwise the extension will not be able to parse the xml correctly.
85+
86+ What happens when properties are missing
87+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88+
89+ When properties or attributes are missing for some or all tests inside the test.xml, testcases are still generated.
90+ However, testcases can only be linked to the requirements if either Partially- or FullyVerifies is filled.
4891
4992Language-Specific Annotations
5093-----------------------------
@@ -58,15 +101,16 @@ C++ (gTest)
58101 See :need: `gd_req__verification_link_tests_cpp `.
59102
60103Rust
61- Use the `` #[record_property] `` attribute macro from the `` test_properties `` crate .
62- See :need: ` gd_req__verification_link_tests_rust ` .
104+ Currently there is no provided official way to do this in Rust .
105+ We are working with the rust community to figure this out .
63106
64107Python (pytest)
65108 Use the ``@add_test_properties `` decorator; the docstring serves as ``Description ``.
66109 See :need: `gd_req__verification_link_tests_python `.
67110
68111See :need: `gd_temp__verification_specification ` for code templates.
69112
113+
70114Running Tests and Building Docs
71115-------------------------------
72116
@@ -84,9 +128,59 @@ Running Tests and Building Docs
84128
85129 The resulting documentation shows backlinks on each requirement that is referenced by at least one test.
86130
131+
132+ How do I use the generated testcases?
133+ -------------------------------------
134+
135+ Testcases can be used in different ways inside and outside your documentation.
136+ You can create lists or pie diagrams to showcase all tests as well as statistics on them.
137+ For example you can show all tests like so
138+
139+ .. code-block :: rst
140+
141+ .. needpie:: Test Results
142+ :labels: passed, failed, skipped
143+ :colors: green, red, orange
144+
145+ type == 'testcase' and result == 'passed'
146+ type == 'testcase' and result == 'failed'
147+ type == 'testcase' and result == 'skipped'
148+
149+
150+ .. needpie :: Test Results
151+ :labels: passed, failed, skipped
152+ :colors: green, red, orange
153+
154+ type == 'testcase' and result == 'passed'
155+ type == 'testcase' and result == 'failed'
156+ type == 'testcase' and result == 'skipped'
157+
158+ Or show the different types of properties in case you want
159+
160+ .. code-block :: rst
161+
162+ .. needpie:: Test Types Used In Testcases
163+ :labels: fault-injection, interface-test, requirements-based, resource-usage
164+ :legend:
165+
166+ type == 'testcase' and test_type == 'fault-injection'
167+ type == 'testcase' and test_type == 'interface-test'
168+ type == 'testcase' and test_type == 'requirements-based'
169+ type == 'testcase' and test_type == 'resource-usage'
170+
171+
172+ .. needpie :: Test Types Used In Testcases
173+ :labels: fault-injection, interface-test, requirements-based, resource-usage
174+ :legend:
175+
176+ type == 'testcase' and test_type == 'fault-injection'
177+ type == 'testcase' and test_type == 'interface-test'
178+ type == 'testcase' and test_type == 'requirements-based'
179+ type == 'testcase' and test_type == 'resource-usage'
180+
181+
87182Limitations
88183-----------
89184
90185- Tests must be executed by Bazel before building docs so ``test.xml `` files exist.
91186- Not compatible with Esbonio / live preview (no ``bazel-testlogs/ `` available).
92- - All mandatory properties must be present; partial metadata causes the test to be silently skipped.
0 commit comments