You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bool result = functionName(/* parameters that will cause error */);
67
+
68
+
// -- Assert --
69
+
// Verify the function fails gracefully (error handling path executes)
70
+
// This verifies that the error handling code path executes correctly.
71
+
XCTAssertFalse(result, @"functionName should fail with error condition");
72
+
}
73
+
```
74
+
75
+
**Untestable Error Paths:**
76
+
77
+
Some error paths cannot be reliably tested in a test environment:
78
+
79
+
-**System calls with hardcoded valid parameters**: Cannot pass invalid parameters to trigger failures
80
+
-**Resource exhaustion scenarios**: System limits may not be enforceable in test environments
81
+
-**Function interposition limitations**: `DYLD_INTERPOSE` only works for dynamically linked symbols; statically linked system calls cannot be reliably mocked
82
+
83
+
**Documenting Untestable Error Paths:**
84
+
85
+
When an error path cannot be reliably tested:
86
+
87
+
1.**Remove the test** if one was attempted but couldn't be made to work
88
+
2.**Add documentation** in the test file explaining:
89
+
- Why there's no test for the error path
90
+
- Approaches that were tried and why they failed
91
+
- That the error handling code path exists and is correct (verified through code review)
92
+
3.**Add a comment** in the source code at the error handling location explaining why it cannot be tested
93
+
4.**Update PR description** to document untestable error paths in the "How did you test it?" section
94
+
95
+
**Test Comment Best Practices:**
96
+
97
+
-**Avoid line numbers** in test comments - they become outdated when code changes
98
+
-**Reference function names and file names** instead of line numbers
99
+
-**Document the error condition** being tested (e.g., "when open() fails")
100
+
-**Explain verification approach** - verify that the error handling path executes correctly rather than capturing implementation details
101
+
40
102
### Commit Guidelines
41
103
42
104
-**Pre-commit Hooks**: This repository uses pre-commit hooks. If a commit fails because files were changed during the commit process (e.g., by formatting hooks), automatically retry the commit. Pre-commit hooks may modify files (like formatting), and the commit should be retried with the updated files.
0 commit comments