Chuyển đến nội dung
Skillpedia
Kiểm thử12k · #11504

fprime-unit-testing

Skill này làm gì

Skill dẫn AI qua việc tạo file kiểm thử đơn vị cho thành phần F Prime, gồm lớp kiểm thử, các ca kiểm thử và đăng ký trong build. Dành cho kỹ sư kiểm thử phần mềm bay F Prime.

Khi nào nên dùng

  • ✓Khi bạn cần kiểm thử đơn vị cho một thành phần F Prime mới hoặc đã thay đổi.
  • ✓Khi bạn muốn tạo khung kiểm thử đơn vị cho một thành phần.
  • ✓Khi bạn cần đăng ký một kiểm thử đơn vị trong build CMake.

Liên kết skill

https://github.com/nasa/fprime/blob/devel/.github/skills/fprime-unit-testing/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/nasa/fprime/blob/devel/.github/skills/fprime-unit-testing/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Hãy thiết lập khung kiểm thử đơn vị cho thành phần F Prime này và thêm kiểm thử cho các lệnh của nó.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI tạo khung kiểm thử, viết lớp kiểm thử và các ca kiểm thử, đăng ký kiểm thử trong build rồi chạy chúng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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
Câu hỏi thường gặp

Tôi có cần biên dịch thành phần trước không?

Có. Skill liệt kê mô hình FPP đã biên dịch và triển khai hoạt động là điều kiện tiên quyết.

Kiểm thử dựa trên quy tắc là gì?

Đó là kiểu kiểm thử skill khuyên dùng khi có thể, vì nó bao quát nhiều hơn so với các kiểm tra viết tay riêng lẻ.

Skill có bao quát các hàm hỗ trợ kiểm thử không?

Có. Skill hướng dẫn cách thiết kế các hàm hỗ trợ như một phần của cấu trúc kiểm thử.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
12k
Vị trí xếp hạng
#11504
Giấy phép
Apache-2.0
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự