Skip to content
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

Swift Testing support #18

Open
dudek-j opened this issue Nov 18, 2024 · 0 comments · May be fixed by #19
Open

Swift Testing support #18

dudek-j opened this issue Nov 18, 2024 · 0 comments · May be fixed by #19

Comments

@dudek-j
Copy link

dudek-j commented Nov 18, 2024

We have started migrating our tests to Swift Testing.

Any asserts from XCTest are treated as no-ops when run in the new framework and vice versa. For example the following tests will pass without any errors or warnings.

import Testing
import XCTest

struct Mytest {
    @Test
    func sample() throws {
        XCTAssertTrue(false)
    }
}

and

import Testing
import XCTest

class MyTest: XCTestCase {
    func test_sample() {
        #expect(false)
    }
}

It would be nice if ViewControllerPresentationSpy also supported the new framework. This can be done by extending the existing asserts with a matching copy of calls to #expect() as in this sample example.

import Testing
import XCTest

func assertText(
    _ text: String, 
    _ label: UILabel, 
    file: StaticString = #filePath, 
    line: UInt = #line, 
    sourceLocation: SourceLocation = #_sourceLocation
) {
    XCTAssertEqual(text, label.text, file: file, line: line)
    #expect(text == label.text, sourceLocation: sourceLocation)
}

This way the assert can be used regardless of which framework is running at any given moment.

@dudek-j dudek-j linked a pull request Dec 4, 2024 that will close this issue
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 a pull request may close this issue.

1 participant