skills/oh-ut-generator/SKILL.md
Generate OpenHarmony C++ unit tests following HWTEST_F framework conventions. Supports Mock strategies, BUILD.gn configuration, NDK/NAPI interfaces, and maintains 75%+ coverage requirements with strict code style consistency. Use when generating unit tests for OpenHarmony C++ source files.
npx skillsauth add openharmonyinsight/openharmony-skills oh-ut-generatorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Generate comprehensive C++ unit tests for OpenHarmony code following HWTEST_F framework conventions.
Invoke this skill when you need to generate unit tests for OpenHarmony C++ source files.
When existing test files exist:
Consistency Threshold: >=70% for important scenarios
// Test fixture structure
class YourServiceTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
std::shared_ptr<YourService> instance_;
};
// Test case format
HWTEST_F(TestClassName, TestCaseName_001, TestSize.Level1)
_001: Normal scenario_002: Exception scenario_003: Boundary scenario_004+: Other special scenarios// Standard smart pointers
SetUp(): instance_ = std::make_shared<YourService>();
TearDown(): instance_ = nullptr;
// OpenHarmony sptr/wptr
SetUp(): instance_ = MakeSptr<YourService>(); // or instance_ = new YourService();
TearDown(): instance_ = nullptr;
auto mock = std::make_shared<MockClass>();
EXPECT_CALL(*mock, Method()).WillOnce(Return(value));
ASSERT_NE(instance_, nullptr); // Must check
EXPECT_EQ(result, expected);
EXPECT_TRUE(condition);
For NDK interfaces (OH_xxx), follow these requirements:
For CJSON library operations:
ohos_unittest("{CamelCase}Test") {
module_out_path = "subsystem/module"
branch_protector_ret = "pac_ret"
sanitize = {
integer_overflow = true
cfi = true
cfi_cross_dso = true
debug = false
}
sources = ["test_file.cpp"] # Alphabetically sorted
include_dirs = ["//include/path"]
deps = [":source_target"]
external_deps = [
"hilog:libhilog",
"c_utils:utils",
"googletest:gtest_main"
]
defines = ["private=public"]
}
The system automatically extracts source file's BUILD.gn configuration:
Detailed specifications are available in the references/ directory:
See the examples/ directory for:
testing
--- name: ohos-req-value-decision description: Use after review meeting to record decision and route to next step. Triggers: 评审决策纪要, 评审结论回流, value decision, 评审接纳, 评审不接纳, 评审退回, 下次重新上会. Do NOT use for feature baseline (ohos-req-feature-baseline), review gate checks (ohos-req-review-gate), or IR generation (ohos-req-feature-to-ir). metadata: author: openharmony scope: common stage: requirements capability: value-decision version: 0.3.0 status: draft tags: - sdd - requirements
development
Use when converting an OpenHarmony requirement document, spec, or design proposal into an OpenHarmony review slide deck (需求评审 / 需求变更评审 / 设计评审 PPTX) — produces the fixed OpenHarmony-branded review-deck structure (OH logo on every page) with architecture/flow diagrams and field tables. Triggers on "需求评审PPT", "需求变更评审", "把需求文档转成评审PPT", "spec转评审PPT", "requirement/spec to review deck". NOT for arbitrary or generic slide decks unrelated to OpenHarmony requirement/design review.
testing
Use when performing the Phase 0 Step 0.5 Review Ready Gate on a 04-feature.md, especially when the user says "evaluate gate", "review readiness", "feature ready?", "should we generate IR", or when the ohos-req-intake-orchestration main session needs a structured Ready / Conditional Ready / Not Ready judgment instead of doing the check inline. Reads 01-04, runs seven fixed checks plus a conditional-items check, and returns a machine-readable JSON summary plus a human-readable table that the main session can route on. Do NOT use for feature baseline generation (ohos-req-feature-baseline), value decision recording (ohos-req-value-decision), or IR generation (ohos-req-feature-to-ir).
testing
--- name: ohos-req-requirement-intake description: Use when importing an OHOS requirement into Phase 0.1, especially for 01-requirement.md, requirement intake, background, user value, scenarios, scope, FR/NFR, affected modules, or priority. Triggers: 需求导入, 01-requirement, 需求基线, RR单号. Do NOT use for feasibility analysis (ohos-req-feasibility-analysis), architecture decision (ohos-req-arch-decision), or feature baseline (ohos-req-feature-baseline). metadata: author: openharmony scope: common