본문으로 건너뛰기
Skillpedia
테스트15k · #10990

principle-test-behavior-not-implementation

하는 일

좋은 테스트를 작성하고 유지하는 규칙을 에이전트에 제공합니다. 리팩터링마다 테스트가 깨지거나, 코드가 잘못되었는데도 테스트가 통과하는 문제로 고민하는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓테스트를 작성하거나, 바꾸거나, 그대로 유지할 때.
  • ✓동작은 그대로인데 리팩터링할 때마다 테스트가 실패하는 경우.
  • ✓동작을 일부러 깨뜨렸는데도 테스트가 계속 통과할 때.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“리팩터링할 때마다 사용자에게 보이는 변화가 없어도 테스트가 깨집니다. 동작을 확인하도록 다시 작성해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 각 테스트를 두 가지 가상의 수정으로 점검합니다. 하나는 동작을 깨뜨리는 수정으로, 테스트가 잡아야 합니다. 다른 하나는 내부만 바꾸는 수정으로, 테스트가 살아남아야 합니다. 어느 점검이든 실패하는 테스트는 다시 쓰거나 삭제하며, 공개 인터페이스를 통해 코드를 실행합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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.

자주 묻는 질문

동작이란 무엇인가요?

반환 값, 오류, 읽을 수 있는 상태, 보낸 메시지처럼 코드 사용자가 관찰할 수 있는 것입니다.

약한 테스트란 무엇인가요?

기대 값을 테스트 대상 코드가 계산하거나, 계약보다 느슨하게 검사하는 테스트입니다.

비공개 헬퍼를 검사해야 하나요?

아닙니다. 비공개 헬퍼와 내부 호출 순서는 구현 세부 사항이지 동작이 아닙니다.

상세 정보

작성자의 원본 설명

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

인기도

GitHub 스타
15k
순위
#10990
라이선스
—
업데이트
2026. 10. 31.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬