Avatar
omochimetaru 9/30/2025 5:39 AM
はい、Suiteオブジェクト自体はただのシンボルみたいなもので状態じゃないので、そこでやっちゃいけない
5:39 AM
Suite単位で共通の初期化をするためにあるのは、Suite Trait の provideScope だと思います。
5:40 AM
struct MySuiteTrait: SuiteTrait & TestScoping { func provideScope( for test: Test, testCase: Test.Case?, performing function: () async throws -> Void ) async throws { print("enter suite scope") defer { print("leave suite scope") } try await function() } } (edited)
5:41 AM
これで、スイートツリーの開始時と終了時に初期化・解放を書けます。
5:42 AM
struct MyTestTrait: TestTrait & TestScoping { func provideScope( for test: Test, testCase: Test.Case?, performing function: () async throws -> Void ) async throws { print("enter test") defer { print("leave test") } try await function() } } こうするとテストの開始・終了を挟める。
5:43 AM
で、Suite Trait だけど子孫の テスト全部を個別に挟む、というのがこう。 struct MyRecursiveSuiteTrait: SuiteTrait & TestScoping { var isRecursive: Bool { true } func provideScope( for test: Test, testCase: Test.Case?, performing function: () async throws -> Void ) async throws { print("enter test") defer { print("leave test") } try await function() } } (edited)