- Home
- Skills
- Openharmonyinsight
- Openharmony Skills
- Oh Ut Generator
oh-ut-generator_skill
- Python
0
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill openharmonyinsight/openharmony-skills --skill oh-ut-generator- SKILL.md6.5 KB
Overview
This skill generates OpenHarmony C++ unit tests following HWTEST_F framework conventions. It produces complete, runnable test cases with mocks, BUILD.gn entries, and NDK/NAPI or CJSON-specific handling while targeting high coverage and consistent style. Use it to automate tests for individual files or specific functions and to extend existing test suites safely.
How this skill works
The generator analyzes a given C++ source file and produces HWTEST_F fixtures and test cases for normal, exception, and boundary scenarios. It creates mock classes when dependencies exist, inserts EXPECT_CALL/ON_CALL expectations, and emits BUILD.gn ohos_unittest targets with matching deps/includes/defines. Special handling is applied for NDK (OH_xxx) and NAPI functions, and CJSON operations, with coverage-driven branching to meet 75%+ requirements.
When to use it
- Adding unit tests for an OpenHarmony C++ source file (single-file or module).
- Generating focused tests for a specific function or API surface.
- Creating mocks and expectations for dependencies automatically.
- Extending an existing test file with new, style-consistent cases.
- Testing NDK/NAPI interfaces or CJSON interactions with lifecycle checks.
Best practices
- Ensure all generated test cases are complete and contain executable assertions.
- Match existing test smart-pointer and assertion styles to keep >=70% consistency.
- Cover normal, exception, and boundary paths for each conditional branch.
- Use generated BUILD.gn entries and verify deps, include_dirs, and defines.
- Always initialize variables, perform null checks, and free allocated resources.
Example use cases
- Generate a full test suite for a service class including SetUp/TearDown and instance_ management.
- Create mocks for a dependency and add EXPECT_CALL checks that validate behavior.
- Produce tests for an OH_xxx NDK interface that validate create/destroy pairing and error codes.
- Append boundary and invalid-parameter tests for functions that parse JSON via cJSON.
- Auto-generate an ohos_unittest BUILD.gn target that mirrors the source target dependencies.
FAQ
No. Every test case is implemented with executable code and assertions; comment-only or placeholder tests are forbidden.
How does it meet coverage targets?
The generator creates test variations for normal, exception, and boundary branches and prioritizes branch/line paths to reach a minimum of 75% coverage, aiming for 85%.