@@ -43,24 +43,66 @@ allows you to customize how the `assertSnapshot` tool behaves for a well-defined
43
43
Rather than overriding ` isRecording ` or ` diffTool ` directly in your tests, you can wrap your test in
44
44
` withSnapshotTesting ` :
45
45
46
- ``` swift
47
- withSnapshotTesting (diffTool : .ksdiff , record : .all ) {
48
- // Assertions in here
46
+ @Row {
47
+ @Column {
48
+ ```swift
49
+ // Before
50
+
51
+ func testFeature() {
52
+ isRecording = true
53
+ diffTool = "ksdiff"
54
+ assertSnapshot(…)
55
+ }
56
+ ```
57
+ }
58
+ @Column {
59
+ ```swift
60
+ // After
61
+
62
+ func testFeature() {
63
+ withSnapshotTesting(record: .all, diffTool: .ksdiff) {
64
+ assertSnapshot(…)
65
+ }
66
+ }
67
+ ```
68
+ }
49
69
}
50
- ```
51
70
52
71
If you want to override the options for an entire test class, you can override the ` invokeTest `
53
72
method of ` XCTestCase ` :
54
73
55
- ``` swift
56
- class FeatureTests : XCTestCase {
57
- override func invokeTest () {
58
- withSnapshotTesting (diffTool : .ksdiff , record : .all ) {
59
- super .invokeTest ()
74
+ @Row {
75
+ @Column {
76
+ ```swift
77
+ // Before
78
+
79
+ class FeatureTests: XCTestCase {
80
+ override func invokeTest() {
81
+ isRecording = true
82
+ diffTool = "ksdiff"
83
+ defer {
84
+ isRecording = false
85
+ diffTool = nil
86
+ }
87
+ super.invokeTest()
88
+ }
89
+ }
90
+ ```
91
+ }
92
+ @Column {
93
+ ```swift
94
+ // After
95
+
96
+ class FeatureTests: XCTestCase {
97
+ override func invokeTest() {
98
+ withSnapshotTesting(diffTool: .ksdiff, record: .all) {
99
+ super.invokeTest()
100
+ }
101
+ }
60
102
}
103
+ ```
61
104
}
62
105
}
63
- ```
64
106
65
107
And if you want to override these settings for _ all_ tests, then you can implement a base
66
108
` XCTestCase ` subclass and have your tests inherit from it.
@@ -117,3 +159,7 @@ struct FeatureTests {
117
159
```
118
160
119
161
That will override the ` diffTool ` and ` record ` options for the entire ` FeatureTests ` suite.
162
+
163
+ > Important: As evident by the usage of ` @_spi(Experimental) ` this API is subject to change. As
164
+ soon as the Swift Testing library finalizes its API for ` CustomExecutionTrait ` we will update
165
+ the library accordingly and remove the ` @_spi ` annotation.
0 commit comments