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
@@ -251,43 +251,45 @@ For a real world use case we modified Apple's [Landmarks](https://developer.appl
251
251
]
252
252
```
253
253
254
-
### `XCTAssertNoDifference`
254
+
### `expectNoDifference`
255
255
256
-
The`XCTAssertEqual`function from `XCTest` allows you to assert that two values are equal, and if they are not the test suite will fail with a message:
256
+
XCTest's`XCTAssertEqual`and Swift Testing's `#expect(_ == _)` both allow you to assert that two values are equal, and if they are not the test suite will fail with a message:
257
257
258
258
```swift
259
259
var other = user
260
260
other.name+="!"
261
261
262
262
XCTAssertEqual(user, other)
263
+
#expect(user == other)
263
264
```
264
265
```text
265
266
XCTAssertEqual failed: ("User(favoriteNumbers: [42, 1729], id: 2, name: "Blob")") is not equal to ("User(favoriteNumbers: [42, 1729], id: 2, name: "Blob!")")
Unfortunately this failure message is quite difficult to visually parse and understand. It takes a few moments of hunting through the message to see that the only difference is the exclamation mark at the end of the name. The problem gets worse if the type is more complex, consisting of nested structures and large collections.
270
+
Unfortunately these failure messages are quite difficult to visually parse and understand. It takes a few moments of hunting through the message to see that the only difference is the exclamation mark at the end of the name. The problem gets worse if the type is more complex, consisting of nested structures and large collections.
269
271
270
-
This library also ships with an `XCTAssertNoDifference` function to mitigate these problems. It works like `XCTAssertEqual` except the failure message uses a nicely formatted diff to show exactly what is different between the two values:
272
+
This library also ships with an `expectNoDifference` function to mitigate these problems. It works like `XCTAssertEqual` and `#expect(_ == _)` except the failure message uses a nicely formatted diff to show exactly what is different between the two values:
271
273
272
274
```swift
273
-
XCTAssertNoDifference(user, other)
275
+
expectNoDifference(user, other)
274
276
```
275
-
```text
276
-
XCTAssertNoDifference failed: …
277
+
```diff
278
+
expectNoDifference failed: …
277
279
278
-
User(
279
-
favoriteNumbers: […],
280
-
id: 2,
281
-
− name: "Blob"
282
-
+ name: "Blob!"
283
-
)
280
+
User(
281
+
favoriteNumbers: […],
282
+
id: 2,
283
+
- name: "Blob"
284
+
+ name: "Blob!"
285
+
)
284
286
285
287
(First: −, Second: +)
286
288
```
287
289
288
-
### `XCTAssertDifference`
290
+
### `expectDifference`
289
291
290
-
This function provides the inverse of `XCTAssertNoDifference`: it asserts that a value has a set of changes by evaluating a given expression before and after a given operation and then comparing the results.
292
+
This function provides the inverse of `expectNoDifference`: it asserts that a value has a set of changes by evaluating a given expression before and after a given operation and then comparing the results.
291
293
292
294
For example, given a very simple counter structure, we can write a test against its incrementing functionality:
293
295
@@ -302,7 +304,7 @@ struct Counter {
302
304
}
303
305
304
306
var counter =Counter()
305
-
XCTAssertDifference(counter) {
307
+
expectDifference(counter) {
306
308
counter.increment()
307
309
} changes: {
308
310
$0.count=1
@@ -316,7 +318,7 @@ By omitting the operation you can write a "non-exhaustive" assertion against a v
316
318
317
319
```swift
318
320
counter.increment()
319
-
XCTAssertDifference(counter) {
321
+
expectDifference(counter) {
320
322
$0.count=1
321
323
// Don't need to further describe how `isOdd` has changed
0 commit comments