-
Notifications
You must be signed in to change notification settings - Fork 112
Expand parameterized testing documentation to mention try/await support and showcase helper pattern #1133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand parameterized testing documentation to mention try/await support and showcase helper pattern #1133
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,37 @@ func makeLargeOrder(count: Int) async throws { | |
- Note: Very large ranges such as `0 ..< .max` may take an excessive amount of | ||
time to test, or may never complete due to resource constraints. | ||
|
||
### Pass the same arguments to multiple test functions | ||
|
||
If you want to pass the same collection of arguments to two or more | ||
parameterized test functions, you can extract the arguments to a separate | ||
function or property and pass it to each `@Test` attribute. For example: | ||
|
||
```swift | ||
extension Food { | ||
static var bestSelling: [Food] { | ||
get async throws { /* ... */ } | ||
} | ||
} | ||
|
||
@Test(arguments: try await Food.bestSelling) | ||
func `Order entree`(food: Food) { | ||
let foodTruck = FoodTruck() | ||
#expect(foodTruck.order(food)) | ||
} | ||
|
||
@Test(arguments: try await Food.bestSelling) | ||
func `Package leftovers`(food: Food) throws { | ||
let foodTruck = FoodTruck() | ||
let container = try #require(foodTruck.container(fitting: food)) | ||
try container.add(food) | ||
} | ||
``` | ||
|
||
> Tip: You can prefix expressions passed to `arguments:` with `try` or `await`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we use tips otherwise in our documentation? I don't mind starting to use them, but I would like to get guidelines for when to use them instead of other callouts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iamleeg Any advice? |
||
> The testing library evaluates them lazily only if it determines that the | ||
> associated test will run. | ||
|
||
### Test with more than one collection | ||
|
||
It's possible to test more than one collection. Consider the following test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel strongly here, but do we need to repeat this for each overload or can we just document it in the article?