Pular para o conteúdo
Tecnologia

Coverage 100% não garante testes bons. Mutation testing introduz bugs. Se testes não detectam, são inúteis.

Conceitos Principais

Mutants

Modificações automáticas no código. + vira -, === vira !==, true vira false. Simula bugs comuns.

Killed vs Survived

Killed: teste detectou mutant. Survived: bug passou. Quanto mais killed, melhor.

Mutation Score

killed / (killed + survived). 80%+ é bom. Mais rigoroso que coverage.

Operators

Arithmetic (+ → -), Conditional (=== → !==), Logical (|| → &&). Cobre erros típicos.

Passo a Passo

  1. Install Stryker: npm install --save-dev @stryker-mutator/core @stryker-mutator/jest-runner. npx stryker init. Escolhe test runner.
  2. Configure stryker.conf: mutate: ["src/**/*.js"], testRunner: "jest", coverage: true. Define quais arquivos mutar.
  3. Run Mutation Testing: npx stryker run. Gera mutants, roda testes. Report mostra survived mutants. Demora (roda tests N vezes).
  4. Analyze Results: HTML report em reports/. Veja survived mutants. Adicione testes para kill. Mutation score > 80%.
  5. CI Integration: Run em CI weekly (não em todo commit, lento). Alert se score cai. Benchmark qualidade.

Boas Praticas

Recomendacoes

• Mutation testing para código crítico

• Target 80%+ mutation score

• Run periodicamente (não todo commit)

• Fix survived mutants

• Combine com coverage tradicional

Erros Comuns

Evite estes erros

• Run em todo commit (muito lento)

• Ignorar survived mutants

• Mutation testing de tudo (overkill)

• Não analisar report

• Confiar apenas em coverage %

Checklist

  • Stryker instalado
  • Config para código crítico
  • Mutation testing executado
  • Mutation score > 80%
  • Survived mutants analisados
  • Testes melhorados