fprime-unit-testing
できること
テストクラス、テストケース、ビルドへの登録を含め、F Primeのコンポーネントの単体テストファイルを作る手順を、AIに案内します。F Primeの飛行ソフトウェアをテストするエンジニア向けです。
使う場面
- ✓新規または変更されたF Primeのコンポーネントに単体テストが必要なとき。
- ✓コンポーネントの単体テストの土台を作ってほしいとき。
- ✓CMakeのビルドに単体テストを登録する必要があるとき。
スキルのリンク
https://github.com/nasa/fprime/blob/devel/.github/skills/fprime-unit-testing/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このF Primeのコンポーネントの単体テストの土台を準備し、コマンドのテストを追加してもらえますか。”
毎週5つの新しいスキル。1分で読めます。
仕組み
AIはテストの土台を生成し、テストクラスとテストケースを書き、テストをビルドに登録して実行します。
技術的な内容(元の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
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
fprime-cmake-build-system
12kエージェントが、CMakeの層を通じて、F Primeの飛行ソフトウェアのプロジェクトにモジュール、ビルドのターゲット、プラットフォームの設定を追加できるよう支援します。
fprime-component-design-fpp
12kエージェントが、承認されたF Primeのコンポーネント要件を、ポート、コマンド、イベント、テレメトリのFPPモデルに変換できるよう支援します。
fprime-component-development
12kエージェントが、要件からインテグレーションテストまで、F Primeのコンポーネントを各開発フェーズで進められるよう支援します。
fprime-component-implementation
12kエージェントが、プロジェクトのルールに従って、F Primeのコンポーネントの自動生成されたハンドラー関数の裏にあるC++のコードを書けるよう支援します。
似ているスキル
test-driven-development
311k機能や修正を作る前に、まず失敗するテストを書き、それが失敗するのを確認してから、合格させる最小のコードを書くようエージェントに教えます。
verification-before-completion
311kタスク、修正、ビルドが完了した、または合格したと主張する前に、実際のチェックを実行し、その出力を読むようエージェントに教えます。
migrate-to-shoehorn
310kテストファイル内の危険な型キャストを、shoehornライブラリに置き換え、テストが部分的なデータを使いつつ型チェックを通るようにします。