fprime-unit-testing
ما الذي تفعله
يرشد الوكيل خلال إنشاء ملفات اختبار الوحدة لمكوّن F Prime، بما فيها صنف الاختبار وحالات الاختبار وتسجيله في البناء. وهي مناسبة للمهندسين الذين يختبرون برمجيات طيران F Prime.
متى تستخدمها
- ✓عندما تحتاج إلى اختبارات وحدة لمكوّن جديد أو معدّل في F Prime.
- ✓عندما تريد إنشاء هيكل اختبار الوحدة لمكوّن.
- ✓عندما تحتاج إلى تسجيل اختبار وحدة في بناء CMake.
رابط المهارة
https://github.com/nasa/fprime/blob/devel/.github/skills/fprime-unit-testing/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“من فضلك جهّز هيكل اختبار الوحدة لمكوّن F Prime هذا، وأضف اختبارات لأوامره.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
يولّد الوكيل هيكل الاختبار، ويكتب صنف الاختبار وحالاته، ويسجلها في البناء، ثم يشغّلها.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من GitHub.
Skill: F Prime Unit Testing
Step-by-step procedure for writing high-quality unit tests for an F Prime component. The full reference for scaffolding, assertion macros, helper functions, TestMain structure, and CMakeLists registration is in the unit testing guide. Follow the guide for implementation details; this skill adds the workflow order and quality criteria.
0 — Prerequisites
| Item | Required |
|---|---|
| Component FPP model compiled | Yes |
Build cache generated (fprime-util generate --ut) |
Yes |
| Component implementation compiles | Yes |
1 — Scaffold, implement, register, run
- Scaffold:
fprime-util impl --ut— rename.templatefiles, delete auto-generated*Ac.*/*GTestBase.*. - Tester class: inherit
<Component>GTestBase, add test methods and helper functions. See Tester class structure and helper functions. - TestMain:
TEST()macros withCOMMENT(...)/REQUIREMENT(...), seedSTest::Random. See TestMain. - CMakeLists.txt:
register_fprime_ut(...)withUT_AUTO_HELPERSandDEPENDS STest. See CMakeLists.txt registration. - Build & run:
fprime-util build --ut,fprime-util check,fprime-util check --coverage. - Consolidate: once the new tests pass, re-read the test diff as
a reviewer would and refactor before opening the PR:
- fold repeated invoke → assert sequences shared by two or more
tests into a Tester helper, or into an existing rule when the
component already has
test/ut/Rules/; - reuse existing helpers and rules before adding new ones;
- drop tests that do not verify the behavior the task added or changed (note remaining coverage gaps as future work);
- re-run
fprime-util checkto confirm nothing regressed.
- fold repeated invoke → assert sequences shared by two or more
tests into a Tester helper, or into an existing rule when the
component already has
2 — Key patterns to enforce
clearHistory()at the start of every test action.component.doDispatch()after every async invocation on active/queued components.- Helper functions for all port invocations and assertion groups —
no raw
invoke_to_*+ASSERT_*in test methods. STest::Pick::any()for port numbers, IDs, sizes where the specific value does not matter.
3 — Rules-based testing (preferred for complex components)
| Criteria | Simple tests | Rules-based |
|---|---|---|
| Few ports, no state machine | Preferred | Overkill |
| Multiple interacting ports | Possible | Preferred |
| Stateful behavior (counters, modes) | Difficult | Preferred |
| Need random / fuzzing coverage | Not possible | Required |
Core constructs (all from TestUtils/RuleBasedTesting.hpp):
FW_RBT_DEFINE_RULE(TesterClass, Group, Rule)— declares a precondition/action pair and a rule struct on the Tester.- Shadow state — a Tester member mirroring observable component state; queried in preconditions, updated in actions.
- Scenarios —
RandomScenario(picks applicable rule at random),BoundedScenario(wraps another, stops after N steps),SequenceScenario(fixed order).
Scaffold with fprime-util new --rule-based-test. For file layout,
implementation patterns, and full examples see the
rules-based testing guide
and the Svc/Ccsds/ApidManager exemplar.
Build note: add every Rules/<GroupName>.cpp and
TestState/TestState.cpp to the SOURCES list in CMakeLists.txt
and include DEPENDS STest.
4 — Quality checklist
- Every input port has at least one test
- Every command has nominal + error-path tests
- Every event asserted (emitted and not-emitted)
- Every telemetry channel asserted after its update action
-
clearHistory()at start of each test action -
doDispatch()after every async invocation on active/queued components - Helper functions used — no raw
invoke_to_*+ASSERT_*in test methods -
STest::Pickfor port numbers, IDs, sizes where specific
الأسئلة الشائعة
هل أحتاج إلى تجميع المكوّن أولا؟
نعم. تذكر المهارة نموذج FPP مترجَما وتنفيذا عاملا كشروط مسبقة.
ما الاختبار القائم على القواعد؟
هو أسلوب اختبار توصي به المهارة حيثما أمكن، لأنه يغطي مساحة أوسع من الفحوص الفردية المكتوبة يدويا.
هل يغطي دوال المساعدة في الاختبارات؟
نعم. يغطي كيفية تصميم دوال المساعدة كجزء من بنية الاختبار.
التفاصيل
الوصف الأصلي من المؤلف
Write F Prime component unit tests. Covers scaffold generation via `fprime-util impl --ut`, the Tester / TestMain / GTestBase pattern, rules-based testing with STest, helper-function design, and the CMakeLists.txt registration. Use whenever creating or extending unit tests for an F Prime component.
repo: nasa/fprime
الشعبية
- نجوم GitHub
- 12k
- الترتيب
- #11504
- الترخيص
- Apache-2.0
- آخر تحديث
- 2/11/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
fprime-cmake-build-system
12kيساعد وكيلك على إضافة وحدات وأهداف بناء وإعدادات منصات إلى مشروع برمجيات طيران F Prime عبر طبقة CMake الخاصة به.
fprime-component-design-fpp
12kيساعد وكيلك على تحويل متطلبات مكوّن F Prime المعتمدة إلى نموذج FPP يصف منافذه وأوامره وأحداثه وقياساته عن بُعد.
fprime-component-development
12kيساعد وكيلك على توجيه مكوّن F Prime عبر كل مرحلة تطوير، من المتطلبات حتى اختبار التكامل.
fprime-component-implementation
12kيساعد وكيلك على كتابة شيفرة C++ خلف دوال المعالجة المولّدة لمكوّن F Prime، باتباع قواعد المشروع.
مهارات مشابهة
test-driven-development
311kيعلّم وكيلك كتابة اختبار فاشل أولًا، ثم رؤيته يفشل، ثم كتابة أصغر شيفرة تنجحه، قبل بناء أي ميزة أو إصلاح.
verification-before-completion
311kيعلّم وكيلك تشغيل فحوصات حقيقية وقراءة نتائجها قبل أن يقول إن المهمة أو الإصلاح أو البناء مكتمل أو ناجح.
migrate-to-shoehorn
310kيستبدل تأكيدات النوع الخطرة في ملفات الاختبار بمكتبة shoehorn، حتى تتمكن الاختبارات من استخدام بيانات جزئية وتجتاز فحوص الأنواع.