fprime-unit-testing
Fungsinya
Skill ini memandu AI membuat berkas tes unit untuk komponen F Prime, termasuk kelas tes, kasus tes, dan pendaftaran build. Skill ini untuk insinyur yang menguji perangkat lunak penerbangan F Prime.
Kapan dipakai
- βSaat Anda memerlukan tes unit untuk komponen F Prime yang baru atau yang diubah.
- βSaat Anda ingin kerangka tes unit dibuat untuk sebuah komponen.
- βSaat Anda perlu tes unit didaftarkan di build CMake.
Link skill
https://github.com/nasa/fprime/blob/devel/.github/skills/fprime-unit-testing/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βTolong siapkan kerangka tes unit untuk komponen F Prime ini dan tambahkan tes untuk perintahnya.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
AI membuat kerangka tes, menulis kelas tes dan kasus tes, mendaftarkan tes di build, lalu menjalankannya.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum
Apakah saya perlu mengompilasi komponen terlebih dahulu?
Ya. Skill ini mencantumkan model FPP yang sudah dikompilasi dan implementasi yang berfungsi sebagai prasyarat.
Apa itu tes berbasis aturan?
Itu adalah gaya pengujian yang direkomendasikan skill ini jika memungkinkan, karena cakupannya lebih luas daripada pemeriksaan manual satu per satu.
Apakah skill ini mencakup fungsi bantu tes?
Ya, skill ini mencakup cara merancang fungsi bantu sebagai bagian dari struktur tes.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 12k
- Peringkat
- #11504
- Lisensi
- Apache-2.0
- Diperbarui
- 2/11/2026
Komentar
- β¦
Skill lain dari repositori ini
fprime-cmake-build-system
12kMembantu agent Anda menambahkan modul, target build, dan pengaturan platform ke proyek perangkat lunak penerbangan F Prime melalui lapisan CMake-nya.
fprime-component-design-fpp
12kMembantu agent Anda mengubah persyaratan komponen F Prime yang sudah disetujui menjadi model FPP untuk port, perintah, event, dan telemetri-nya.
fprime-component-development
12kMembantu agent Anda memandu komponen F Prime melalui setiap fase pengembangan, dari persyaratan hingga tes integrasi.
fprime-component-implementation
12kMembantu agent Anda menulis kode C++ di balik fungsi handler yang dihasilkan untuk komponen F Prime, dengan mengikuti aturan proyek.
Skill serupa
test-driven-development
311kMengajari agent Anda menulis tes yang gagal dulu, melihatnya gagal, lalu menulis kode terkecil yang lulus, sebelum membangun fitur atau perbaikan apa pun.
verification-before-completion
311kMengajari agent Anda menjalankan pemeriksaan nyata dan membaca keluarannya sebelum menyatakan tugas, perbaikan, atau build sudah selesai atau lulus.
migrate-to-shoehorn
310kMengganti type cast berisiko di file tes Anda dengan pustaka shoehorn, sehingga tes bisa memakai data parsial dan tetap lulus pemeriksaan tipe.