principle-test-behavior-not-implementation
O que ela faz
Dá ao assistente uma regra para escrever e manter bons testes. É para desenvolvedores cujos testes quebram em toda refatoração ou continuam passando quando o código está errado.
Quando usar
- ✓Quando você escreve, altera ou mantém um teste.
- ✓Quando testes falham em toda refatoração, mesmo sem mudança de comportamento.
- ✓Quando um teste continua passando depois que você quebra deliberadamente o comportamento.
Link da skill
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation/SKILL.mdCopie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.
Como usar
O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.
Mensagem pronta para colar
Para Claude Code, Codex ou Cursor: rode na pasta do projeto e a skill fica instalada.
Baixe o SKILL.md e coloque na pasta de skills do seu agente.
Exemplo do que pedir para a IA
“Nossos testes quebram toda vez que refatoramos, mesmo quando nada visível ao usuário mudou. Reescreva-os para verificar o comportamento.”
5 skills novas por semana. 1 minuto de leitura.
Como funciona
O assistente confere cada teste contra duas edições imaginadas: uma que quebra o comportamento, que o teste deve pegar, e uma que muda só os internos, que o teste deve suportar. Ele reescreve ou apaga os testes que falham em qualquer uma das duas checagens, conduzindo o código pela interface pública.
Conteúdo técnico (SKILL.md original)
Texto original do autor, em inglês, direto do GitHub.
Test Behavior, Not Implementation
A test is a claim about what the code does for its users: a caller, an end user, or another service. Behavior is what those users can observe through the interface they use. That includes return values, errors, state they can read back, and effects on systems outside the code, such as a request sent, a row written, or a message emitted. Implementation is what they cannot observe: private helpers, internal call order, intermediate data, and which internal collaborator did the work.
Judge each test against two imagined edits:
- Break the behavior. Make the code return a wrong value, skip an effect, or do the effect twice. If the test still passes, it proves nothing. The usual causes are an assertion looser than the contract, an expected value computed by the code under test, a restated constant or prompt string that never runs the code that reads it, and an assertion on data that the test built itself.
- Change the internals. Keep every observable result the same and restructure the code underneath. If the test now fails, it is pinned to the implementation. It will need a rewrite on every refactor and still catches no bug.
Keep a test that catches the first edit and survives the second. Rewrite or delete the rest. To write a test that does both, drive the code through its users' interface with a concrete input. Derive the expected value from the requirement, not from a run of the code. Assert what the contract promises, no less and no more.
The contract decides, not the shape of the assertion. When "an empty cart never charges" is the promise, an assertion that the payment client got no call is behavior. Pair it with a case where the charge happens, so that the test shows it can see a call. The payload that a mocked external service receives is behavior, because that service observes it. A call to an internal helper is implementation, because no user can see it. An empty list is the exact answer when no record matches, and a hollow check when the test only needs some result. An exact error message pins wording that no caller reads. The error type that callers branch on is the contract.
A test can pin an invariant instead of a call, such as a key that must exist in two tables or a compile-time type check. The invariant is the behavior.
Perguntas frequentes
O que conta como comportamento?
O que os usuários do código podem observar, como valores de retorno, erros, estado legível e efeitos como uma mensagem enviada.
O que é um teste fraco?
Um teste cujo valor esperado é calculado pelo próprio código testado, ou cuja asserção é mais frouxa do que o contrato.
Os testes devem verificar funções auxiliares privadas?
Não. Funções auxiliares privadas e a ordem interna de chamadas são detalhes de implementação, não comportamento.
Detalhes
Descrição original do autor
Apply when you write, change, or keep a test. Assert what the code's users can observe, so that the test fails when that behavior breaks and keeps passing when only the internals change.
repo: cursor/plugins
Popularidade
- Estrelas no GitHub
- 15 mil
- Posição no ranking
- #10990
- Licença
- —
- Atualizada em
- 31/10/2026
Comentários
- …
Mais skills deste repositório
advisor
15 milPermite que seu agente consulte um segundo modelo mais forte em pontos-chave, como antes de uma decisão importante ou quando está travado em um erro, se você ativar.
check-agent-compatibility
15 milExecuta uma verificação completa de quão bem agentes de código de IA conseguem iniciar, verificar e documentar um repositório, e devolve uma única pontuação de compatibilidade com os principais problemas.
cli-for-agents
15 milEnsina seu agente a projetar ou revisar ferramentas de linha de comando para que agentes de IA consigam executá-las sem perguntas, com textos de ajuda claros e exemplos.
continual-learning
15 milMantém suas notas do AGENTS.md atualizadas, entregando o trabalho de revisar conversas passadas a um atualizador de memória dedicado.
Skills parecidas
test-driven-development
311 milEnsina seu agente a escrever primeiro um teste que falha, ver a falha e depois escrever o menor código que passa, antes de criar qualquer funcionalidade ou correção.
verification-before-completion
311 milEnsina seu agente a rodar verificações reais e ler a saída antes de afirmar que uma tarefa, correção ou build está concluído ou passando.
migrate-to-shoehorn
310 milSubstitui conversões de tipo arriscadas nos seus arquivos de teste pela biblioteca shoehorn, para que os testes usem dados parciais e ainda passem na checagem de tipos.