티스토리 뷰
- WWDC 24 > Meet Swift Testing
- WWDC 24 > Go further with Swift Testing
[1] 언제 @Suite 를 직접 붙여야하는가 ?
문서:
A type containing test functions is automatically a test suite and can be optionally annotated with the @Suite attribute.
WWDC 와 문서에서 말하는 것 처럼,
테스트 함수를 포함하는 타입은 자동으로 테스트 스위트가 되기 때문에
@Suite 를 직접 붙일 필요가 없다.
즉 두개는 똑같기 때문에 굳이 @Suite 를 안붙여줘도 됨.
그럼 @Suite 를 언제 붙이면 좋을까 ?
displayName 을 별도로 지정해주고 싶을 때, traits 지정이 필요할 때 사용하면 됨.
예를들어
[ 참고 ]
SuiteTrait 과 TestTrait 은 모두 Trait 을 상속하고 있기 때문에
trait 종류가 거의 동일함.
[2] 모든 trait 은 nested test suite 에도 같이 적용되는가 ?
기본적으로 suite 에 적용한 trait 은 해당 suite 가 포함하는 test 함수 및 nested suite 에 다 적용됨
(가장 쉬운 예로 tag trait 을 생각해보면 됨)
모든 trait 이 상속된다고 어디에 시원하게 나와있지 않지만, 그런 것 같음!
가장 의심이 되는 두가지인 serialized, timeLimit trait 을 아래에서 살펴보자.
우선 serialized trait 은 상속된다고 WWDC 에서 언급됨.
Running tests serially or in parallel 문서에도 다음과 같이 나와있음.
This trait is recursively applied: if it is applied to a suite, any parameterized tests or test suites contained in that suite are also serialized (as are any tests contained in those suites, and so on.)
timeLimit trait 도 테스트해보니 잘 상속되고
Limiting the running time of tests 문서 에도 다음과 같이 나와있음.
When a time limit is applied to a test suite, it’s recursively applied to all test functions and child test suites within that suite.
그리고 여러 timeLimit trait 이 적용될 때, 가장 짧은 시간의 trait 이 사용된다고 함.
⭐️ If multiple time limit traits apply to a test, the shortest time limit is used.
테스트 해보니 정말 가장 가까운 trait 이 아니라 가장 짧은 시간의 trait 이 적용되는 모습 을 확인할 수 있었음.
+ enable, disable 도 함께 확인차 테스트 해봤는데, 예상대로 disabled 가 enabled 보다 더 우선순위로 먹힘.
☑️ 정리
-> 모든 trait 은 재귀적으로 test function, nested suite 에 적용된다고 생각하면 될 듯.
-> 하지만 헷갈리면 안되는 게 serialized 는 살짝 성격이 다름. timeLimit 처럼 각 test function 마다 개별적으로 timeLimit 이 걸리는 게 아니라 suite 단위 임. suite 내의 test 들이 serial 하게 실행되는 것이니까.
문서의 예제코드 + 주석을 읽어보면 바로 이해가능.
@Suite(.serialized) struct FoodTruckTests {
@Test(arguments: Condiment.allCases) func refill(condiment: Condiment) {
// This function will be invoked serially, once per condiment, because the
// containing suite has the .serialized trait.
}
@Test func startEngine() async throws {
// This function will not run while refill(condiment:) is running. One test
// must end before the other will start.
}
}
[3] Swift Testing 과 XCTest 가 같이 있을 때, 테스트 옵션 지정한 건 둘다 적용 되는 건가 ?
Swift Testing 은 디폴트가 병렬 실행이고 순차 실행을 원하면 serialized trait 을 붙여준다.
반면 XCTest 는 디폴트가 순차 실행이고 병렬로 실행하기 위해 scheme 에서 테스트 옵션을 바꿔줬다.
Xcode 몇버전 부터 바뀐 건지 기억이 안나는데, Test Plan 전에는 이렇게 세팅해줬고
지금 (Xcode16) 은 이 동선으로 들어가서 TestPlan > Options 로 설정한다.
병렬 옵션에 이렇게 3개가 제공된다.
- Disabled : Swift Testing, XCTest 모두 병렬 X
- Swift Testing Only : Swift Testing 병렬 O, XCTest 병렬 X
- Enabled (If Possible) : Swift Testing, XCTest 모두 병렬 O
Enabled 에 If Possible 이 있는 경우는
XCTest 는 MacOS 랑 simulator 에서만 병렬 실행이 가능하기 때문인 듯.
Enabled (If Possible) 이 디폴트 값이니까 이제는 XCTest 도 디폴트가 병렬임!
참고로
XCTestCase 별로 병렬 옵션을 ON/OFF 할 수 있는 프로퍼티가 혹시 추가되었나 문서를 봤는데 없는 듯 함!
개별 지정은 Swift Testing 만..
[4] XCTest 를 Swift Testing 으로 완전히 Migration 할 수 있는가 ?
대부분은 그렇다.
마이그레이션 문서: Migrating a test from XCTest
문서에 너무 잘 나와있음.
문서에서 주의깊게 볼 것은 XCTFail 이 record 랑 대응된다는 점. (XCTFail 같은 거 없는 줄 알았음 ;;;)
그리고 expectation fullfill -> confirmation 도!
하지만 계속 XCTest 를 써야하는 케이스도 있다.
Continue to use XCTest for User Interface Tests and Performance Tests.
[5] DisplayName 은 언제 쓰면 좋을까 ?
Suite 나 Test 이름을 명확하게 지정해주면 DisplayName 은 필요없어보이는데
언제 쓰면 좋을까 ?
WWDC 에서는 가독성을 위해 띄어쓰기 하는 용도로 dislayname 을 사용했다.
이것도 좋고 parameterized test 에서 파라미터들이 많아서
테스트가 길어질 때 테스트 네임을 짧게 하고 displayName 을 길게 하는 식으로 사용해도 좋을 것 같다.
[6] Tag 를 중첩시키면 어떻게 표시되나 ?
[ 테스트 > 태그 ]
tag 별로 해당하는 테스트함수가 모두 나옴
상위 Tag 로 검색해도 하위 테스트 함수까지 잘 나옴
[ 테스트 리포트 ]
태그 다 붙어서 나옴
검색에 상위 Tag 를 제외해도 하위 테스트 (다른 태그를 달고 있는 테스트) 는 나옴.
[ 테스트 플랜 ]
상위 Tag 를 Exclude 하면 하위 테스트까지 다 exclude 됨.
'🍏 > Swift' 카테고리의 다른 글
[Swift] 매크로 (Macro) (1) | 2024.12.07 |
---|---|
[Swift] @isolated(any) (4) | 2024.11.15 |
[Swift] @unchecked, @preconcurrency, @retroactive (9) | 2024.11.06 |
[Swift] Noncopyable (~Copyable) (3) | 2024.10.26 |
[Swift] Typed throws (0) | 2024.10.13 |
- Total
- Today
- Yesterday
- Watch App for iOS App vs Watch App
- Flutter 로딩
- ribs
- flutter dynamic link
- 장고 URL querystring
- cocoapod
- Django FCM
- 플러터 얼럿
- Flutter Clipboard
- github actions
- Python Type Hint
- Flutter getter setter
- flutter deep link
- DRF APIException
- Django Firebase Cloud Messaging
- 장고 Custom Management Command
- Flutter Text Gradient
- Sketch 누끼
- Django Heroku Scheduler
- 구글 Geocoding API
- drf custom error
- METAL
- flutter build mode
- Flutter Spacer
- SerializerMethodField
- Dart Factory
- PencilKit
- 플러터 싱글톤
- ipad multitasking
- flutter 앱 출시
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |