Skip to content

Instantly share code, notes, and snippets.

@davbeck
Created September 21, 2023 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davbeck/bb6e7b2301a9669f6fd241982233c30b to your computer and use it in GitHub Desktop.
Save davbeck/bb6e7b2301a9669f6fd241982233c30b to your computer and use it in GitHub Desktop.
// example of what the macros could be expanded into for XCTestCase
final class PostsCoordinatorTests: XCTestCase {
func test_addPost() async throws {
let coordinator = PostsCoordinator()
coordinator.createPost()
XCTAssert(coordinator.postCount == 1)
}
func test_hasExistingPosts_countsPosts() async throws {
let coordinator = PostsCoordinator()
coordinator.posts = [
.build(),
.build(),
.build(),
]
XCTAssert(coordinator.postCount == 3)
}
func test_hasExistingPosts_addPost() async throws {
let coordinator = PostsCoordinator()
coordinator.posts = [
.build(),
.build(),
.build(),
]
coordinator.createPost()
XCTAssert(coordinator.postCount == 4)
}
}
#Describe(PostsCoordinator.self) {
// code in describe and context gets re-run for each test
let coordinator = PostsCoordinator()
#Test("add post") {
coordinator.createPost()
#expect(coordinator.postCount == 1)
}
#Context("has existing posts") {
coordinator.posts = [
.build(),
.build(),
.build(),
]
#Test("counts posts") {
#expect(coordinator.postCount == 3)
}
#Test("add post") {
coordinator.createPost()
#expect(coordinator.postCount == 4)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment