Skip to content

Commit 034665f

Browse files
pahmannPandaeDo
authored andcommitted
Improve verification templates for code
Resolves: #193 Signed-off-by: Philipp Ahmann <[email protected]>
1 parent 97121e5 commit 034665f

File tree

2 files changed

+85
-50
lines changed

2 files changed

+85
-50
lines changed

process/process_areas/verification/guidance/verification_process_reqs.rst

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Process Requirements
4747

4848

4949
More information can be found in the :need:`gd_guidl__verification_guide`, :need:`doc_concept__verification_process`,
50-
and :need:`gd_guidl__verification_specification`.
50+
and :need:`gd_guidl__verification_specification` .
5151

5252
.. gd_req:: Linking Requirements to Tests (C++)
5353
:id: gd_req__verification_link_tests_cpp
@@ -57,30 +57,12 @@ Process Requirements
5757
:complies: std_req__iso26262__support_6432
5858

5959

60-
For linking C++ test suites to requirements **record properties** shall be used. Attributes
60+
For linking C++ tests to requirements **record properties** shall be used. Attributes
6161
which are common for all test cases can be specified in the Setup Function (SetUp()), the other
6262
attributes which are specific for each test case need to be specified within the test case:
6363

64-
.. code-block:: cpp
64+
A more detailed description of how to link code to requirements looks like is available in the :ref:`verification_template_cpp`
6565

66-
class TestSuite : public ::testing::Test{
67-
public:
68-
void SetUp() override
69-
{
70-
RecordProperty("TestType", "<TestType>");
71-
RecordProperty("DerivationTechnique", "<DerivationTechnique>");
72-
...
73-
}
74-
};
75-
76-
TEST_F(TestSuite, <Test Case>)
77-
{
78-
RecordProperty("PartiallyVerifies", "ID_2, ID_3, ...");
79-
RecordProperty("FullyVerifies", "ID_4, ID_5, ...");
80-
RecordProperty("Description", "<Description>");
81-
82-
ASSERT ...
83-
}
8466

8567
.. gd_req:: Linking Requirements to Tests (Python)
8668
:id: gd_req__verification_link_tests_python
@@ -101,17 +83,8 @@ Process Requirements
10183
For allowed values for test_type & derivation_technique please check :need:`gd_req__verification_link_tests`
10284
Further more, this decorator will also check if your test has a `docstring` which should act as the description of the test.
10385

86+
A more detailed description of how to link code to requirements looks like is available in the :ref:`verification_template_python`
10487

105-
.. code-block:: python
106-
107-
@add_test_properties(
108-
partially_verifies=["tool_req__docs_dd_link_source_code_link"],
109-
test_type="requirements-based",
110-
derivation_technique="requirements-analysis",
111-
)
112-
def test_group_by_need_empty_list():
113-
"""Test grouping empty list of needlinks."""
114-
...
11588

11689
.. gd_req:: Linking Requirements to Tests (Rust)
11790
:id: gd_req__verification_link_tests_rust
@@ -122,19 +95,7 @@ Process Requirements
12295

12396
For linking Rust tests to requirements **#[record_property]** shall be used:
12497

125-
.. code-block:: rust
126-
127-
use test_properties::record_property;
128-
129-
#[record_property("PartiallyVerifies", "ID_2, ID_3, ...")]
130-
#[record_property("FullyVerifies", "ID_4, ID_5, ...")]
131-
#[record_property("Description", "<Description>")]
132-
#[record_property("TestType", "<TestType>")]
133-
#[record_property("DerivationTechnique", "<DerivationTechnique>")]
134-
#[test]
135-
fn test_case_function() {
136-
...
137-
}
98+
A more detailed description of how to link code to requirements looks like is available in the :ref:`verification_template_rust`
13899

139100
.. gd_req:: Independence
140101
:id: gd_req__verification_independence

process/process_areas/verification/guidance/verification_templates.rst

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,44 @@ Verification Templates
2020
The sections below are seen as typical ways when writing tests and their specification.
2121
Their usage differs based on the selected testing framework and the implementation language of the module(s).
2222

23-
gTest
24-
-----
23+
C++
24+
---
2525

26-
gTest is a commonly used and accepted test framework to write test cases for C/C++ code.
26+
For C++ code gTest is a commonly used and accepted test framework to write test cases for C/C++ code.
2727

2828
Each test case requires a link to one or more requirement/design element.
29-
A more detailed description of how to link code to requirements is available here: :need:`gd_req__verification_link_tests_cpp`
29+
30+
For linking C++ tests to requirements **record properties** shall be used. Attributes
31+
which are common for all test cases can be specified in the Setup Function (SetUp()), the other
32+
attributes which are specific for each test case need to be specified within the test case:
33+
34+
Below code is exemplary and can be used as a template when writing test cases.
35+
36+
.. _verification_template_cpp:
37+
38+
C++ Properties Template
39+
^^^^^^^^^^^^^^^^^^^^^^^
40+
41+
.. code-block:: cpp
42+
43+
class TestSuite : public ::testing::Test{
44+
public:
45+
void SetUp() override
46+
{
47+
RecordProperty("TestType", "<TestType>");
48+
RecordProperty("DerivationTechnique", "<DerivationTechnique>");
49+
...
50+
}
51+
};
52+
53+
TEST_F(TestSuite, <Test Case>)
54+
{
55+
RecordProperty("PartiallyVerifies", "ID_2, ID_3, ...");
56+
RecordProperty("FullyVerifies", "ID_4, ID_5, ...");
57+
RecordProperty("Description", "<Description>");
58+
59+
ASSERT ...
60+
}
3061
3162
When writing test cases using gTest, they shall follow the recommendations from the official gTest documentation.
3263
For very basic start follow http://google.github.io/googletest/primer.html
@@ -41,7 +72,29 @@ Details on the definition an the test organization in rust can be found here:
4172
https://doc.rust-lang.org/book/ch11-03-test-organization.html
4273

4374
Each test case requires a link to one or more requirement/design element.
44-
A more detailed description of how to link code to requirements is available here: :need:`gd_req__verification_link_tests_rust`
75+
76+
Below code is exemplary and can be used as a template when writing test cases.
77+
78+
.. _verification_template_rust:
79+
80+
Rust Properties Template
81+
^^^^^^^^^^^^^^^^^^^^^^^^
82+
83+
For linking Rust tests to requirements **#[record_property]** shall be used:
84+
85+
.. code-block:: rust
86+
87+
use test_properties::record_property;
88+
89+
#[record_property("PartiallyVerifies", "ID_2, ID_3, ...")]
90+
#[record_property("FullyVerifies", "ID_4, ID_5, ...")]
91+
#[record_property("Description", "<Description>")]
92+
#[record_property("TestType", "<TestType>")]
93+
#[record_property("DerivationTechnique", "<DerivationTechnique>")]
94+
#[test]
95+
fn test_case_function() {
96+
...
97+
}
4598
4699
When writing test cases in rust, they shall follow the recommendations from the official rust documentation.
47100
https://doc.rust-lang.org/book/ch11-01-writing-tests.html
@@ -54,7 +107,28 @@ When writing test cases in python, this should be done using pytest.
54107
Note that python unittest does not support metatags and therefore should not be considered as test framework.
55108

56109
Each test case requires a link to one or more requirement/design element.
57-
A more detailed description of how to link code to requirements is available here: :need:`gd_req__verification_link_tests_python`
110+
111+
For linking python tests to requirements **metadata** shall be used.
112+
113+
For allowed values for test_type & derivation_technique please check :need:`gd_req__verification_link_tests`
114+
115+
Below code is exemplary and can be used as a template when writing test cases.
116+
117+
.. _verification_template_python:
118+
119+
Python Properties Template
120+
^^^^^^^^^^^^^^^^^^^^^^^^^^
121+
122+
.. code-block:: python
123+
124+
@add_test_properties(
125+
partially_verifies=["tool_req__docs_dd_link_source_code_link"],
126+
test_type="requirements-based",
127+
derivation_technique="requirements-analysis",
128+
)
129+
def test_group_by_need_empty_list():
130+
"""Test grouping empty list of needlinks."""
131+
...
58132
59133
When writing test cases in python, they shall follow the recommendations from the official python and community documentation.
60134
https://docs.python-guide.org/writing/tests/

0 commit comments

Comments
 (0)