Post

Replies

Boosts

Views

Activity

How Do I Test an API With Swift Concurrency
I'm trying to test an API I'm writing with Structured Concurrency. I prefer to run my tests with continueAfterFailure = false so that I may establish preconditions on my tests. At the moment my test is:     func testRssUrl() async throws {         self.continueAfterFailure = false         let xml = PodcastXml.url(url)         let feed = try await xml.feed         let rssFeed: RSSFeed? = feed.rssFeed         XCTAssertNil(rssFeed) // Included for this sample         XCTAssertNotNil(rssFeed)         validate(zebraFeed: rssFeed!)     } My expectation of Swift Concurrency is that the try await should hold the method, until xml.feed resolves to a value or throws. Either of the XCTAssertNil or XCTAssertNotNil should fail (in the actual test, I'm not using NotNil). As written, between the two asserts and the try, validate(zebraFeed: ) should never be called because of continueAfterFailure. Yet it is. The test still fails because XCTAssertNil is failing, which is my actual expectation. Test execution should also be stopping there. What am I missing?
2
0
1.2k
Mar ’22
How Do I Test an API With Swift Concurrency
I'm trying to test an API I'm writing with Structured Concurrency. I prefer to run my tests with continueAfterFailure = false so that I may establish preconditions on my tests. At the moment my test is:     func testRssUrl() async throws {         self.continueAfterFailure = false         let xml = PodcastXml.url(url)         let feed = try await xml.feed         let rssFeed: RSSFeed? = feed.rssFeed         XCTAssertNil(rssFeed) // Included for this sample         XCTAssertNotNil(rssFeed)         validate(zebraFeed: rssFeed!)     } My expectation of Swift Concurrency is that the try await should hold the method, until xml.feed resolves to a value or throws. Either of the XCTAssertNil or XCTAssertNotNil should fail (in the actual test, I'm not using NotNil). As written, between the two asserts and the try, validate(zebraFeed: ) should never be called because of continueAfterFailure. Yet it is. The test still fails because XCTAssertNil is failing, which is my actual expectation. Test execution should also be stopping there. What am I missing?
Replies
2
Boosts
0
Views
1.2k
Activity
Mar ’22