Pular para o conteúdo
Skillpedia
Testes15 mil · #10990

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.md

Copie 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

Use esta skill para me ajudar: https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

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

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas