principle-test-behavior-not-implementation
Skill này làm gì
Cung cấp cho agent một quy tắc viết và giữ test tốt. Dành cho lập trình viên có test bị hỏng ở mọi lần refactor, hoặc vẫn pass khi code sai.
Khi nào nên dùng
- ✓Khi bạn viết, thay đổi hoặc giữ một test.
- ✓Khi test thất bại ở mỗi lần refactor dù hành vi không đổi.
- ✓Khi một test vẫn pass sau khi bạn cố ý phá vỡ hành vi.
Liên kết skill
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Test của chúng tôi bị hỏng mỗi lần refactor, dù không có gì thay đổi với người dùng. Hãy viết lại chúng để kiểm tra hành vi.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent kiểm tra từng test theo hai chỉnh sửa tưởng tượng: một chỉnh sửa phá vỡ hành vi, mà test phải bắt được, và một chỉnh sửa chỉ thay đổi phần nội bộ, mà test phải sống sót. Nó viết lại hoặc xóa các test thất bại ở một trong hai kiểm tra, và điều khiển code qua giao diện công khai.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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.
Câu hỏi thường gặp
Hành vi là gì?
Những gì người dùng code có thể quan sát, như giá trị trả về, lỗi, trạng thái đọc được và các hiệu ứng như một tin nhắn được gửi đi.
Test yếu là gì?
Test mà giá trị kỳ vọng do chính code đang test tính ra, hoặc khẳng định lỏng hơn hợp đồng.
Test có nên kiểm tra các hàm nội bộ không?
Không. Hàm nội bộ và thứ tự gọi nội bộ là chi tiết cài đặt, không phải hành vi.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 15k
- Vị trí xếp hạng
- #10990
- Giấy phép
- —
- Cập nhật
- 31/10/2026
Bình luận
- …
Thêm skill từ kho mã này
advisor
15kCho agent hỏi ý kiến một mô hình thứ hai mạnh hơn tại các điểm then chốt, như trước quyết định lớn hoặc khi bị kẹt ở lỗi, nếu bạn bật nó.
check-agent-compatibility
15kKiểm tra xem coding agent AI có khởi động, xác minh và ghi tài liệu được cho một repository không, rồi trả về một điểm tương thích và vấn đề chính.
cli-for-agents
15kDạy agent thiết kế hoặc rà soát công cụ dòng lệnh để các coding agent AI chạy được mà không cần lời nhắc, với trợ giúp rõ ràng và ví dụ.
continual-learning
15kGiữ các ghi chú AGENTS.md của bạn cập nhật bằng cách giao việc rà soát các cuộc trò chuyện trước cho một trình cập nhật bộ nhớ chuyên dụng.
Skill tương tự
test-driven-development
311kDạy agent của bạn viết kiểm thử thất bại trước, xem nó thất bại, rồi viết đoạn mã ngắn nhất để vượt qua trước khi làm bất kỳ tính năng hay bản sửa nào.
verification-before-completion
311kDạy agent của bạn chạy kiểm tra thực tế và đọc kết quả đầu ra trước khi khẳng định một việc, bản sửa hoặc bản build đã hoàn thành hay vượt qua.
migrate-to-shoehorn
310kThay các ép kiểu rủi ro trong tệp kiểm thử bằng thư viện shoehorn, để các bài kiểm thử dùng dữ liệu một phần vẫn qua được kiểm tra kiểu.