Agent Skills › nasa/fprime › fprime-unit-testing

fprime-unit-testing

GitHub

指导编写F Prime组件单元测试,涵盖脚手架生成、Tester类结构、STest规则测试及CMake注册。强调通过helper函数封装和规则复用提升质量,并新增提交后重构与回归检查流程以确保代码整洁。

.github/skills/fprime-unit-testing/SKILL.md nasa/fprime

Trigger Scenarios

需要为F Prime组件创建或扩展单元测试时 执行fprime-util impl --ut进行测试脚手架生成时 优化现有单元测试结构或修复测试回归问题时

Install

npx skills add nasa/fprime --skill fprime-unit-testing -g -y
More Options

Non-standard path

npx skills add https://github.com/nasa/fprime/tree/devel/.github/skills/fprime-unit-testing -g -y

Use without installing

npx skills use nasa/fprime@fprime-unit-testing

指定 Agent (Claude Code)

npx skills add nasa/fprime --skill fprime-unit-testing -a claude-code -g -y

安装 repo 全部 skill

npx skills add nasa/fprime --all -g -y

预览 repo 内 skill

npx skills add nasa/fprime --list

SKILL.md

Frontmatter
{
    "name": "fprime-unit-testing",
    "description": "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."
}

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

  1. Scaffold: fprime-util impl --ut — rename .template files, delete auto-generated *Ac.* / *GTestBase.*.
  2. Tester class: inherit <Component>GTestBase, add test methods and helper functions. See Tester class structure and helper functions.
  3. TestMain: TEST() macros with COMMENT(...) / REQUIREMENT(...), seed STest::Random. See TestMain.
  4. CMakeLists.txt: register_fprime_ut(...) with UT_AUTO_HELPERS and DEPENDS STest. See CMakeLists.txt registration.
  5. Build & run: fprime-util build --ut, fprime-util check, fprime-util check --coverage.
  6. 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 check to confirm nothing regressed.

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::Pick for port numbers, IDs, sizes where specific value doesn't matter
  • Boundary values tested (min/max buffer size, port index 0 and max)
  • Rules-based testing for stateful / multi-port components (≥ 1000 random steps)
  • No dynamic memory after construction
  • REQUIREMENT("...") and COMMENT("...") macros present
  • Consolidation pass done: shared sequences folded into helpers or rules, off-task tests removed
  • fprime-util check passes

Version History

  • 1d70340 Current 2026-10-19 21:54

    新增测试通过后的整理步骤:审查diff、重构重复逻辑、复用现有辅助函数与规则、移除无效测试,并重新运行检查以确认无回归。

  • 7d8f579 2026-08-20 11:33

Same Skill Collection

.github/skills/agent-skill-authoring/SKILL.md
.github/skills/ai-session-report/SKILL.md
.github/skills/ai-session-summary/SKILL.md
.github/skills/ci-test-runtime-policy/SKILL.md
.github/skills/fprime-cmake-build-system/SKILL.md
.github/skills/fprime-component-design-fpp/SKILL.md
.github/skills/fprime-component-development/SKILL.md
.github/skills/fprime-component-implementation/SKILL.md
.github/skills/fprime-component-integration-test/SKILL.md
.github/skills/fprime-component-requirements/SKILL.md
.github/skills/fprime-component-unit-test/SKILL.md
.github/skills/fprime-ground-input-tracing/SKILL.md
.github/skills/fprime-hardware-input-tracing/SKILL.md
.github/skills/fprime-topology-development/SKILL.md
.github/skills/jpl-design-principles/SKILL.md
.github/skills/maintainer-lookup/SKILL.md
.github/skills/post-inline-review/SKILL.md
.github/skills/pr-diff-scoping/SKILL.md
.github/skills/prompt-injection-precheck/SKILL.md
.github/skills/re-review-state/SKILL.md
.github/skills/triage-classifier/SKILL.md
.github/skills/write-system-functional-doc/SKILL.md
.github/skills/fprime-cpp-design/SKILL.md
.github/skills/fprime-maintenance/SKILL.md

Metadata

Files
0
Version
1d70340
Hash
433a0a2a
Indexed
2026-08-20 11:33

홈 - 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-24 13:17
浙ICP备14020137号-1