ohos-test-ut-generation

Generate OpenHarmony HWTEST/HWTEST_F unit tests and BUILD.gn configurations.

31|6|Updated Jan 29, 2026
One-click install
npx skills add https://github.com/openharmonyinsight/openharmony-skills --skill ohos-test-ut-generation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ohos-test-ut-generation
Source: https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/ohos-test-ut-generation
Command: npx skills add https://github.com/openharmonyinsight/openharmony-skills --skill ohos-test-ut-generation

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

It solves the time-consuming and error-prone work of writing OpenHarmony testfwk_developer_test-compliant HWTEST/HWTEST_F unit tests for C/C++ code, including correct macro usage, test levels, naming, and BUILD.gn wiring.

Core Features & Use Cases

  • Scaffold compliant unit test files: Produces test plans and code that follow OpenHarmony’s HWTEST rules (including mandatory using namespace testing::ext;, TestSize.Level*, and proper @tc.* annotations).
  • Design test cases from source: Helps analyze target source APIs and derive a structured set of scenarios (normal, exception, boundary, state).
  • Generate GN build configuration: Guides creation of ohos_unittest targets (imports, deps, module output path format, and cflags_cc for private/protected access).
  • Optional style alignment from existing tests: When there are existing tests, it leverages analysis to match local macro usage, naming, comment style, and Level formatting.

Example use case: You are asked to write new HWTEST/HWTEST_F cases for a subsystem module that has public APIs plus some private logic; you want deterministic, gate-compliant tests and a correct test/unittest/BUILD.gn setup.

Quick Start

Tell the assistant the exact OpenHarmony module/function(s) you need to test and the intended output location under test/unittest/, and ask it to generate HWTEST/HWTEST_F test cases plus the corresponding BUILD.gn target.

Frequently Asked Questions about ohos-test-ut-generation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write OpenHarmony C++ unit tests that pass gate checks?

To write OpenHarmony C++ unit tests that pass gate checks, generate testfwk_developer_test compliant HWTEST cases using `using namespace testing::ext`, mandatory `TestSize.Level*`, and proper `@tc.*` annotations.

What must be included in an OpenHarmony BUILD.gn for ohos_unittest?

An OpenHarmony BUILD.gn for ohos_unittest must include `import("//build/test.gni")`, correct `module_out_path` formatting, and `gtest_main` deps to pass gate checks.

How do I test private or protected C++ functions in OpenHarmony unit tests?

To test private or protected C++ functions in OpenHarmony unit tests, add optional `cflags_cc` flags in your BUILD.gn to expose internal class members for your HWTEST_F cases.

What annotations are required for HWTEST macros in OpenHarmony testfwk_developer_test?

HWTEST macros in OpenHarmony testfwk_developer_test require `@tc.name`, `@tc.desc`, `@tc.type`, `@tc.require` annotations and a mandatory `TestSize.Level*` parameter to pass gate rules.

Can I generate OpenHarmony test cases by analyzing existing source code?

Yes, you can generate OpenHarmony test cases by analyzing target source APIs to derive structured scenarios covering normal, exception, boundary, and state test cases for your C/C++ code.

Does OpenHarmony unit test generation support matching existing test styles?

OpenHarmony unit test generation supports style alignment by analyzing existing tests to match local macro usage, naming conventions, comment style, and Level formatting in new HWTEST cases.