principle-test-behavior-not-implementation
ما الذي تفعله
تمنح هذه المهارة وكيلك قاعدة لكتابة الاختبارات الجيدة والحفاظ عليها. وهي لمطوّرين تتكسر اختباراتهم مع كل إعادة هيكلة، أو تنجح رغم خطأ الكود.
متى تستخدمها
- ✓عندما تكتب اختبارًا أو تغيّره أو تحتفظ به.
- ✓عندما تفشل الاختبارات مع كل إعادة هيكلة رغم بقاء السلوك كما هو.
- ✓عندما يظل اختبار ناجحًا بعد أن تكسر السلوك عمدًا.
رابط المهارة
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“تنكسر اختباراتنا في كل مرة نعيد فيها الهيكلة، حتى لو لم يتغير شيء يلاحظه المستخدم. أعد كتابتها لتتحقق من السلوك.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
يفحص وكيلك كل اختبار مقابل تعديلين متخيلين: أحدهما يكسر السلوك ويجب أن يلتقطه الاختبار، والآخر يغيّر الداخل فقط ويجب أن يتحمله. ثم يعيد كتابة الاختبارات أو يحذفها إذا فشلت في أي فحص، ويشغّل الكود عبر واجهته العامة.
المحتوى التقني (ملف 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
- الترخيص
- —
- آخر تحديث
- 31/10/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
advisor
15kيتيح لوكيلك استشارة نموذج ثانٍ أقوى عند نقاط مفصلية، مثل قبل قرار كبير أو عند تعثره في خطأ، إذا فعّلت ذلك.
check-agent-compatibility
15kيُجري فحصاً شاملاً لمدى قدرة وكلاء البرمجة بالذكاء الاصطناعي على تشغيل المستودع والتحقق منه وتوثيقه، ويعيد درجة توافق واحدة مع أهم المشكلات.
cli-for-agents
15kيعلّم وكيلك تصميم أدوات سطر الأوامر أو مراجعتها، حتى يستطيع وكلاء الذكاء الاصطناعي تشغيلها دون مطالبات، مع نصوص مساعدة واضحة وأمثلة.
continual-learning
15kيحافظ على ملاحظاتك في AGENTS.md محدّثة، بتسليم مهمة مراجعة المحادثات السابقة إلى مُحدِّث ذاكرة مخصص.
مهارات مشابهة
test-driven-development
311kيعلّم وكيلك كتابة اختبار فاشل أولًا، ثم رؤيته يفشل، ثم كتابة أصغر شيفرة تنجحه، قبل بناء أي ميزة أو إصلاح.
verification-before-completion
311kيعلّم وكيلك تشغيل فحوصات حقيقية وقراءة نتائجها قبل أن يقول إن المهمة أو الإصلاح أو البناء مكتمل أو ناجح.
migrate-to-shoehorn
310kيستبدل تأكيدات النوع الخطرة في ملفات الاختبار بمكتبة shoehorn، حتى تتمكن الاختبارات من استخدام بيانات جزئية وتجتاز فحوص الأنواع.