swift-testing icon indicating copy to clipboard operation
swift-testing copied to clipboard

API or mechanism to perform an action once before/after running all of the tests in a suite type

Open stmontgomery opened this issue 2 years ago • 1 comments

Description

We should have an API or mechanism to perform an action once inside a suite type before or after running all of that suite's tests.

Conceptually, this would be similar to XCTest's class-level +setUp and +tearDown APIs, or what some other testing libraries call "BeforeAll" and "AfterAll". However, for a more modern Swift solution, it may be better to use a closure- or scoped access- style API, since that interoperates better with Swift concurrency and allows using @TaskLocal.

rdar://103616215

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

swift-testing version/commit hash

No response

Swift & OS version (output of swift --version && uname -a)

No response

stmontgomery avatar Sep 28 '23 22:09 stmontgomery

I think the right basic shape for this is some protocol, i.e.:

protocol CustomWhateverable {
static func beforeAll(in suiteType: Self.Type) async throws
static func afterAll(in suiteType: Self.Type) async throws
}

Or something like that. Runner can then detect that a suite type conforms to this protocol and, if so, trivially call those functions at the appropriate times.

grynspan avatar Sep 29 '23 18:09 grynspan