Testing & CI/CD
XCTest, URLProtocol mocking, GitHub Actions e Fastlane
Testes automatizados são a base de qualquer SDK confiável. Em Swift, XCTest + MockURLProtocol permitem testar networking sem rede real, e CI com GitHub Actions garante que cada PR é validada.
Pirâmide de Testes
| Nível | Quantidade | Velocidade | Escopo | Exemplo |
|---|---|---|---|---|
| Unit | Muitos | Milissegundos | Uma função/classe | RetryPolicy.delay(forAttempt:) |
| Integration | Alguns | Segundos | Múltiplos componentes | APIClient + MockURLProtocol |
| UI/E2E | Poucos | Minutos | Fluxo completo | XCUITest do fluxo de verificação |
Convenções de Nomenclatura
| Padrão | Formato | Exemplo |
|---|---|---|
| Given-When-Then | test_givenX_whenY_thenZ | test_givenExpiredToken_whenRefresh_thenReturnsNewToken |
| Method-State-Expected | test_method_state_expected | test_execute_serverError_retriesThreeTimes |
| Should | testMethodShouldBehavior | testCircuitBreakerShouldOpenAfterThreshold |
Qual a diferença entre XCTest e o novo Swift Testing framework?
Swift Testing (iOS 16+) usa macros
#expect e @Test em vez de XCTAssert e prefixo test. Suporta parameterized tests nativamente, tags para organização, e melhor integração com Swift concurrency. XCTest ainda é necessário para UI tests e apps que suportam iOS < 16.