Ohos test graphics3d static api unit test

From openharmonyinsight/openharmony-skills · View interactive version

Ohos test graphics3d static api unit test is an AI agent skill from the GitHub repository openharmonyinsight/openharmony-skills. Use when generating unit tests for ETS/ArkTS static API classes in OpenHarmony graphic_3d module, when adding new test cases for MaterialETS, CameraETS, SceneETS or similar wrapper classes, or when setting up test environment for GTest-based ETS unit tests

How to use this skill

Skill file

Graphics 3D API Unit Test Generator

Overview

Guide for generating ETS/ArkTS static API unit tests based on OpenHarmony GTest framework. Provides test generation workflow, naming conventions, and core patterns.

When to Use

Do NOT use when:

Quick Reference

Naming Conventions

| Element | Convention | Example |

|---------|------------|---------|

| Test class name | <Module>ETSUnitTest | MaterialETSUnitTest |

| Test case name | <Class>_<Method>_<Number> | MaterialETS_Create_001 |

| Test file name | <module>_ets_unit_test.cpp | material_ets_unit_test.cpp |

Test Macros

| Macro | Purpose |

|-------|---------|

| HWTEST_F | Fixed test fixture (required for all ETS unit tests) |

Test Levels: Use appropriate TestSize.Level0-Level4 based on test complexity.

Selection Rule

See UNITTEST_GUIDE.md "Test Case Macros" section for complete Level0-Level4 definitions.

Required Comment Template

/**
 * @tc.name: <TestCaseName>
 * @tc.desc: <Description>
 * @tc.type: FUNC / PERF
 */

Core Pattern: AAA Testing

Use Arrange-Act-Assert pattern:

/**
 * @tc.name: MaterialETS_Create_001
 * @tc.desc: Test MaterialETS creation and initialization
 * @tc.type: FUNC
 */
HWTEST_F(MaterialETSUnitTest, MaterialETS_Create_001, TestSize.Level1)
{
    auto material = std::make_shared<MaterialETS>();
    EXPECT_TRUE(material->IsValid());  // EtsTest provides engine context automatically
}

Implementation Workflow

  1. Create test file: api_unit_test/<module>_ets_unit_test.cpp
  2. Write test cases: Use AAA pattern with required annotations
  3. Update BUILD.gn: Add file to sources list

Complete implementation details: UNITTEST_GUIDE.md provides:

For loading guidance, see "When to Load References" section below.

When to Load References

✅ Load UNITTEST_GUIDE.md when:

❌ Do NOT Load when:

Rule: Start with SKILL.md. Load UNITTEST_GUIDE.md only when blocked or setting up new environment.

Link: UNITTEST_GUIDE.md (load only when above conditions apply)

Common Mistakes

| Issue | Solution |

|-------|----------|

| Header not found | Check BUILD.gn include_dirs |

| Library not found | Ensure libAGPDLL.z.so deployed |

| Tests interfere | Use SetUp/TearDown for isolation |

NEVER Do This

| ❌ Wrong | ✅ Right | Reason |

|----------|----------|--------|

| MaterialETS_Test | MaterialETSUnitTest | OpenHarmony requires UnitTest suffix |

| MaterialETS_Create | MaterialETS_Create_001 | Test naming MUST include _Number suffix |

| Skip @tc.name | Always add annotation | Required for test report generation |

| Use GTest macro directly | Use HWTEST_F macro | OpenHarmony test framework requires it |

| Write test without annotations | Include complete annotation block | Missing annotations break test discovery |

Real-World Impact

Tests generated following this skill:

References

| Document | Description |

|----------|-------------|

| UNITTEST_GUIDE.md | Complete BUILD.gn template, EtsTest base class, environment setup |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.