Skip to content

Swift Testing Implementation#6

Merged
ethan-vanheerden merged 12 commits intomainfrom
swift-testing
Nov 22, 2024
Merged

Swift Testing Implementation#6
ethan-vanheerden merged 12 commits intomainfrom
swift-testing

Conversation

@ethan-vanheerden
Copy link
Copy Markdown
Collaborator

This PR introduces a Swift Testing-based solution for TestableCombinePublishers.

  1. It creates a new SwiftTestingTestableCombinePublishers target which mimics the existingTestableCombinePublishers target, but with no usage of the XCTest library.
    • This new target was created so that clients explicitly need to opt into the Swift Testing version - as XCTest and Swift Testing can have undefined behavior when they are used in the same test suite.
  2. I also created a new TestableCombinePublishersUtility target which houses shared logic between the XCTest and Swift Testing implementations - i.e. AutomaticallyEquatable

The only different between the XCTest and Swift Testing implementation is that the Swift Testing implementation utilizes async/await:

TestableCombinePublishers

SwiftTestingTestableCombinePublishers

func testExpectEquatableValue() {
        ["cool"]
            .publisher
            .expect("cool")
            .waitForExpectations(timeout: 1)
}
@Test func expectEquatableValue() async {
        await ["cool"]
            .publisher
            .expect("cool")
            .waitForExpectations(timeout: 1)
}

@ethan-vanheerden ethan-vanheerden marked this pull request as draft November 15, 2024 20:07
Copy link
Copy Markdown
Owner

@albertbori albertbori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Ethan! Thanks a ton for taking a stab at this. It looks really good. I left a handful of comments for tidying things up. Can't wait to get this merged!

Edit: I'm also curious if there's opportunity here to reshape the expectation API by utilizing Combine Publisher's value parameter, which returns an async sequence of elements from the publisher. The reason I didn't do this originally is because I didn't have a timeout mechanism. Now that we do, assuming that ["cool"].publisher.value supports cooperative cancellation, we may be able to reshape the expectation code.

Regardless, I think we can explore that later as part of a new major version. You're on the right track here with this PR.

Comment thread Package.swift Outdated
@ethan-vanheerden ethan-vanheerden marked this pull request as ready for review November 19, 2024 21:05
Comment thread README.md
Comment thread README.md
Comment thread README.md Outdated
Comment thread README.md Outdated
Copy link
Copy Markdown
Owner

@albertbori albertbori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Fantastic work!

@ethan-vanheerden ethan-vanheerden merged commit fad93ca into main Nov 22, 2024
@ethan-vanheerden ethan-vanheerden deleted the swift-testing branch November 25, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants