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
@@ -17,20 +17,21 @@ Currently, when an issue arises during a test, the only possible outcome is to m
17
17
18
18
### Use Cases
19
19
20
-
-Warning about a Percentage Discrepancy in Image Comparison:
21
-
- Scenario: When comparing two images to assess their similarity, a warning can be triggered if there's a 95% pixel match, while a test failure is set at a 90% similarity threshold.
22
-
- Reason: In practices like snapshot testing, minor changes (such as a timestamp) might cause a discrepancy. Setting a 90% match as a pass ensures test integrity. However, a warning at 95% alerts testers that, although the images aren't identical, the test has passed, which may warrant further investigation.
20
+
- Warning about a Percentage Discrepancy in Image Comparison:
21
+
- Scenario: When comparing two images to assess their similarity, a warning can be triggered if there's a 95% pixel match, while a test failure is set at a 90% similarity threshold.
22
+
- Reason: In practices like snapshot testing, minor changes (such as a timestamp) might cause a discrepancy. Setting a 90% match as a pass ensures test integrity. However, a warning at 95% alerts testers that, although the images aren't identical, the test has passed, which may warrant further investigation.
23
23
- Warning for Duplicate Argument Inputs in Tests:
24
-
- Scenario: In a test library, issue a warning if a user inputs the same argument twice, rather than flagging an error.
25
-
- Reason: Although passing the same argument twice might not be typical, some users may have valid reasons for doing so. Thus, a warning suffices, allowing flexibility without compromising the test's execution.
24
+
- Scenario: In a test library, issue a warning if a user inputs the same argument twice, rather than flagging an error.
25
+
- Reason: Although passing the same argument twice might not be typical, some users may have valid reasons for doing so. Thus, a warning suffices, allowing flexibility without compromising the test's execution.
26
26
- Warning for Recoverable Unexpected Events:
27
-
- Scenario: During an integration test where data is retrieved from a server, a warning can be issued if the primary server is down, prompting a switch to an alternative server. Usually mocking is the solution for this but may not test everything needed for an integration test.
28
-
- Reason: Since server downtime might happen and can be beyond the tester's control, issuing a warning rather than a failure helps in debugging and understanding potential issues without impacting the test's overall success.
27
+
- Scenario: During an integration test where data is retrieved from a server, a warning can be issued if the primary server is down, prompting a switch to an alternative server. Usually mocking is the solution for this but may not test everything needed for an integration test.
28
+
- Reason: Since server downtime might happen and can be beyond the tester's control, issuing a warning rather than a failure helps in debugging and understanding potential issues without impacting the test's overall success.
29
29
- Warning for a retry during setup for a test:
30
-
- Scenario: During test setup part of your code may be configured to retry, it would be nice to notify in the results that a retry happened
31
-
- Reason: This makes sense to be a warning and not a failure because if the retry succeeds the test may still verify the code correctly
30
+
- Scenario: During test setup part of your code may be configured to retry, it would be nice to notify in the results that a retry happened
31
+
- Reason: This makes sense to be a warning and not a failure because if the retry succeeds the test may still verify the code correctly
32
32
33
33
## Proposed solution
34
+
34
35
We propose introducing a new property on `Issue` in Swift Testing called `severity`, that represents if an issue is a `warning` or an `error`.
35
36
The default Issue severity will still be `error` and users can set the severity when they record an issue.
/// The severity level for an issue which should be noted but is not
52
53
/// necessarily an error.
53
54
///
@@ -66,13 +67,15 @@ extension Issue {
66
67
```
67
68
68
69
### Recording Non-Failing Issues
70
+
69
71
To enable test authors to log non-failing issues without affecting test results, we provide a method for recording such issues:
70
72
71
73
```swift
72
74
Issue.record("My comment", severity: .warning)
73
75
```
74
76
75
77
Here is the `Issue.record` method definition with severity as a parameter.
78
+
76
79
```swift
77
80
/// Record an issue when a running test fails unexpectedly.
78
81
///
@@ -92,13 +95,14 @@ Here is the `Issue.record` method definition with severity as a parameter.
92
95
severity: Severity = .error,
93
96
sourceLocation: SourceLocation =#_sourceLocation
94
97
) ->Self
95
-
98
+
96
99
// ...
97
100
```
98
101
99
102
### Issue Type Enhancements
100
103
101
104
The Issue type is enhanced with two new properties to better handle and report issues:
105
+
102
106
-`severity`: This property allows access to the specific severity level of an issue, enabling more precise handling of test results.
103
107
104
108
```swift
@@ -112,7 +116,9 @@ public var severity: Severity { get set }
112
116
}
113
117
114
118
```
119
+
115
120
-`isFailure`: A boolean property to determine if an issue results in a test failure, thereby helping in result aggregation and reporting.
121
+
116
122
```swift
117
123
extensionIssue {
118
124
// ...
@@ -132,6 +138,7 @@ extension Issue {
132
138
```
133
139
134
140
Example usage of `severity` and `isFailure`:
141
+
135
142
```swift
136
143
// ...
137
144
withKnownIssue {
@@ -147,7 +154,7 @@ This revision aims to clarify the functionality and usage of the `Severity` enum
147
154
148
155
### Integration with supporting tools
149
156
150
-
Issue severity will be in the event stream output when a `issueRecorded` event occurs. This will be a breaking change because some tools may assume that all `issueRecorded` events are failing. Due to this we will be bumping the event stream version and v1 will maintain it's behavior and not output any events for non failing issues. We will also be adding `isFailure` to the issue so that clients will know if the issue should be treated as a failure.
157
+
Issue severity will be in the event stream output when a `issueRecorded` event occurs. This will be a breaking change because some tools may assume that all `issueRecorded` events are failing. Due to this we will be bumping the event stream version and v1 will maintain it's behavior and not output any events for non failing issues. We will also be adding `isFailure` to the issue so that clients will know if the issue should be treated as a failure.
151
158
152
159
The JSON event stream ABI will be amended correspondingly:
153
160
@@ -198,7 +205,7 @@ For more details on how to checkout a branch for a package refer to this: https:
198
205
- Naming of `isFailure` vs. `isFailing`: We evaluated whether to name the property `isFailing` instead of `isFailure`. The decision to use `isFailure` was made to adhere to naming conventions and ensure clarity and consistency within the API.
199
206
200
207
- Severity-Only Checking: We deliberated not exposing `isFailure` and relying solely on `severity` checks. However, this was rejected because it would require test authors to overhaul their code should we introduce additional severity levels in the future. By providing `isFailure`, we offer a straightforward way to determine test outcome impact, complementing the severity feature.
201
-
- Naming `Severity.error``Severity.failure` instead because this will always be a failing issue and test authors often think of test failures. Error and warning match build naming conventions and XCTest severity naming convention.
208
+
- Naming `Severity.error``Severity.failure` instead because this will always be a failing issue and test authors often think of test failures. Error and warning match build naming conventions and XCTest severity naming convention.
0 commit comments