jonreid / ViewControllerPresentationSpy

Unit test presented and dismissed iOS view controllers, including alerts and action sheets
MIT License
148 stars 15 forks source link

Swift Testing support #18

Open dudek-j opened 2 weeks ago

dudek-j commented 2 weeks ago

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.