CI/CD sem testes é deploy cego. Automatize unit, integration e E2E. Gate deploys com coverage e test success.
Conceitos Principais
Test Pipeline
Lint → Unit → Integration → E2E. Fail fast: unit primeiro. E2E apenas se anteriores passam.
Parallel Execution
Roda testes em paralelo. Matrix testing: Node 18, 20. Multiple OS. Reduz tempo 5x.
Test Artifacts
Coverage reports, screenshots, videos. Upload em falha. Debug post-mortem.
Quality Gates
Coverage > 80%. Zero critical bugs. Tests pass. Block deploy se não atende.
Passo a Passo
- GitHub Actions Workflow: .github/workflows/test.yml: on push, pull_request. jobs: test (runs: npm test), coverage (upload to codecov).
- Matrix Testing: strategy: matrix: node-version [18, 20]. os: [ubuntu, macos]. Testa combinações.
- Cache Dependencies: uses: actions/cache@v3 with path: node_modules, key: npm-${{ hashFiles("package-lock.json") }}. Build 5x mais rápido.
- Upload Artifacts: uses: actions/upload-artifact@v3 with name: coverage, path: coverage/. Download depois.
- Required Checks: GitHub Settings: Branch protection. Require tests passing. Block merge se falha.
Boas Praticas
Recomendacoes
• Run tests em todo push/PR
• Parallel execution
• Cache dependencies
• Fail fast (unit antes de E2E)
• Upload artifacts em falha
• Required checks para merge
Erros Comuns
Evite estes erros
• Testes apenas em main (tarde demais)
• Não usar cache (build lento)
• E2E bloqueiam pipeline (lentos)
• Não salvar artifacts (debug difícil)
• Testes opcionais (ignorados)
Checklist
- GitHub Actions configurado
- Tests rodando em PR
- Matrix testing se aplicável
- Cache dependencies ativo
- Artifacts salvos em falha
- Required checks habilitado