Saltar al contenido
Skillpedia
Pruebas15 mil · #10990

principle-test-behavior-not-implementation

Qué hace

Ofrece al asistente una regla para escribir y mantener buenas pruebas. Está pensada para desarrolladores cuyas pruebas se rompen en cada refactorización o siguen pasando cuando el código es incorrecto.

Cuándo usarla

  • ✓Cuando escribes, cambias o conservas una prueba.
  • ✓Cuando las pruebas fallan en cada refactorización aunque el comportamiento no haya cambiado.
  • ✓Cuando una prueba sigue pasando después de romper deliberadamente el comportamiento.

Link de la skill

https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Nuestras pruebas se rompen cada vez que refactorizamos, aunque nada visible para el usuario haya cambiado. Reescríbelas para comprobar el comportamiento.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

El asistente comprueba cada prueba frente a dos cambios imaginados: uno que rompe el comportamiento, que la prueba debe detectar, y otro que solo cambia los detalles internos, que la prueba debe soportar. Reescribe o elimina las pruebas que fallan cualquiera de los dos controles, manejando el código a través de su interfaz pública.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de 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.

Preguntas frecuentes

¿Qué cuenta como comportamiento?

Lo que los usuarios del código pueden observar, como valores devueltos, errores, estado legible y efectos como un mensaje enviado.

¿Qué es una prueba débil?

Una cuyo valor esperado lo calcula el propio código bajo prueba, o cuya aserción es más laxa que el contrato.

¿Deben las pruebas comprobar funciones auxiliares privadas?

No. Las funciones auxiliares privadas y el orden de llamadas internas son detalles de implementación, no comportamiento.

Detalles

Descripción original del 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

Popularidad

Estrellas en GitHub
15 mil
Posición en el ranking
#10990
Licencia
—
Actualizada
31/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas