[Accepted] A New Direction for Testing in Swift

It would be good to have some guidance from the language team about the direction and timelines for these features. Without these, it pretty much stops Swift Testing being able to be adopted in any server-side Swift framework, package or app

10 Likes

I believe you can mostly work around this with a CustomExecutionTrait, as it can run async work before and after the test. It's not ideal, but it would mean while we're waiting for to async deinit we could do async setup and teardown as part of each test.

2 Likes

Question: Being able to insert tests side-by-side to the according implemention that should be tested (right?), is it then possible to test private parts of the code? (I know there is some theory why only the public API should be part of unit tests, but there might be complicated private stuff that one might like to have tests available for.)

1 Like

Properties and read-only subscripts do support throws:

struct Foo {
    var throwingProperty: Bool {
        get throws {
            return true
        }
    }

    subscript(foo: Int)-> Bool {
        get throws {
            return true
        }
    }
}
1 Like

This is an area we're interested in exploring as a future direction, but it requires compiler and/or linker changes to support it (otherwise you'd end up shipping debug or test code in your build products.)

This is mentioned in our documentation here.

2 Likes

learn something new every day! :slight_smile:

1 Like