Traceability matrix in Testing Fundamentals - Build an Automation Script
import unittest class TraceabilityMatrixTest(unittest.TestCase): def setUp(self): # Sample data simulating the traceability matrix self.requirements = ['REQ-001', 'REQ-002', 'REQ-003'] self.test_cases = ['TC-101', 'TC-102', 'TC-103', 'TC-104'] # Mapping from requirements to test cases self.matrix = { 'REQ-001': ['TC-101', 'TC-102'], 'REQ-002': ['TC-103'], 'REQ-003': ['TC-104'] } def test_requirements_have_test_cases(self): for req in self.requirements: with self.subTest(requirement=req): self.assertIn(req, self.matrix, f"Requirement {req} missing in matrix") self.assertTrue(len(self.matrix[req]) > 0, f"Requirement {req} has no linked test cases") def test_test_cases_linked_to_existing_requirements(self): all_linked_test_cases = [] for req, tcs in self.matrix.items(): for tc in tcs: all_linked_test_cases.append(tc) for tc in all_linked_test_cases: self.assertIn(tc, self.test_cases, f"Test case {tc} linked but does not exist") def test_no_missing_requirements_or_test_cases(self): # Check all requirements in matrix are known for req in self.matrix.keys(): self.assertIn(req, self.requirements, f"Matrix has unknown requirement {req}") # Check all test cases in matrix are known for tcs in self.matrix.values(): for tc in tcs: self.assertIn(tc, self.test_cases, f"Matrix has unknown test case {tc}") if __name__ == '__main__': unittest.main()
This test script uses Python's unittest framework to automate verification of a traceability matrix.
setUp() prepares sample data representing requirements, test cases, and their links.
test_requirements_have_test_cases checks each requirement has linked test cases.
test_test_cases_linked_to_existing_requirements verifies all linked test cases exist in the test case list.
test_no_missing_requirements_or_test_cases ensures the matrix does not contain unknown requirements or test cases.
Assertions include clear messages to help identify issues.
This structure makes the test easy to read and maintain.
Now add data-driven testing with 3 different sets of requirements and test cases to verify the matrix for each set.
Practice
traceability matrix in software testing?Solution
Step 1: Understand the role of a traceability matrix
A traceability matrix connects requirements with their corresponding test cases to ensure all requirements are tested.Step 2: Compare options with this role
Only To link requirements to test cases ensuring coverage describes linking requirements to tests, which is the main purpose.Final Answer:
To link requirements to test cases ensuring coverage -> Option AQuick Check:
Traceability matrix = links requirements to tests [OK]
- Confusing traceability matrix with bug tracking
- Thinking it manages project schedules
- Assuming it writes test code automatically
Solution
Step 1: Identify the format of a traceability matrix
A traceability matrix is typically a table that maps requirement IDs to their corresponding test case IDs.Step 2: Eliminate unrelated options
Options A, C, and D describe bug lists, architecture diagrams, and manuals, which are not traceability matrices.Final Answer:
A table mapping requirements IDs to test case IDs -> Option AQuick Check:
Traceability matrix = table mapping requirements to tests [OK]
- Confusing it with bug reports
- Thinking it is a flowchart or diagram
- Mixing it up with user documentation
Requirement ID | Test Case ID R1 | TC1 R2 | TC2 R3 | TC3, TC4
Which requirement has multiple test cases linked?
Solution
Step 1: Read the traceability matrix snippet
Requirement R3 is linked to two test cases: TC3 and TC4.Step 2: Identify which requirement has multiple test cases
Only R3 has multiple test cases; R1 and R2 have one each.Final Answer:
R3 -> Option CQuick Check:
Multiple test cases linked = R3 [OK]
- Ignoring multiple test cases listed
- Choosing requirement with single test case
- Misreading the table rows
Solution
Step 1: Understand the problem
Missing test cases for requirements means incomplete test coverage.Step 2: Choose the corrective action
The best fix is to add test cases for those missing requirements to ensure coverage.Final Answer:
Add test cases for the missing requirements -> Option BQuick Check:
Fix missing tests by adding them [OK]
- Ignoring missing tests
- Removing requirements without discussion
- Deleting matrix unnecessarily
Req ID | Test Case ID R1 | TC1 R2 | TC2 R3 | TC3 R4 | TC4 R5 | TC5
During testing, TC3 and TC5 fail. What should you do to maintain traceability and quality?
Solution
Step 1: Analyze test results and traceability
Failures in TC3 and TC5 mean requirements R3 and R5 are not met.Step 2: Maintain traceability and quality
Update the matrix to reflect failed tests and create defect reports for fixing issues.Final Answer:
Update the matrix to mark R3 and R5 as failed and create defect reports -> Option DQuick Check:
Mark failures and report defects to maintain quality [OK]
- Removing requirements due to test failure
- Ignoring test failures
- Restarting testing without tracking defects
Ready to prove it?
Pass the test and this pattern moves unknown
