tdd

Write TDD tests for NG Component Pattern methods with direct invocation and state reset.

14|8|Updated Oct 29, 2024
One-click install
npx skills add https://github.com/openharmony/arkui_ace_engine --skill tdd-openharmony
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tdd
Source: https://github.com/openharmony/arkui_ace_engine/tree/main/.claude/skills/tdd
Command: npx skills add https://github.com/openharmony/arkui_ace_engine --skill tdd-openharmony

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides practical guidelines and templates to write robust TDD tests for NG Component Pattern methods (e.g., OnModifyDone, OnDirtyLayoutWrapperSwap), reducing flaky tests and enforcing consistency.

Core Features & Use Cases

  • Direct method invocation: write tests that call the target methods directly to exercise the intended code paths.
  • State reset discipline: reset all potentially interfering state before running tests to ensure clean baselines.
  • API verification: use Grep/Read techniques to confirm method names and signatures align with source definitions.
  • Branch coverage: create paired tests for true/false branches to improve code coverage.
  • No magic numbers: promote named constants to avoid hard-coded values.
  • Self-checklist and templates: rely on references/test-template.md and self-checklist.md to maintain quality.

Quick Start

Start by reading the SKILL.md for core principles, then review references/test-template.md for concrete templates. Create independent test cases that directly invoke the target methods, reset state prior to invocation, and verify branch outcomes with appropriate assertions. Use the given naming conventions and avoid magic numbers; run the existing test suite to validate coverage.

Frequently Asked Questions about tdd

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

FAQPage Schema
How do I write TDD tests for NG Component Pattern methods like OnModifyDone?

To write TDD tests for NG Component Pattern methods like OnModifyDone, directly invoke the target methods in your tests, reset all potentially interfering state before execution, and verify API signatures using Grep techniques to ensure alignment with source definitions.

What is the best way to achieve branch coverage when unit testing NG components?

The best way to achieve branch coverage for NG components is to create paired tests that explicitly exercise the true and false branches of your conditional logic, ensuring comprehensive code coverage and reducing flaky tests through consistent state management.

Why do my NG component tests fail due to inconsistent state between test cases?

NG component tests fail due to inconsistent state when previous test executions interfere with the current baseline; enforcing state reset discipline before running each test ensures a clean environment and reduces flaky test results.

How do I verify method signatures match source definitions before writing unit tests?

You verify method signatures match source definitions before writing unit tests by applying API verification techniques, specifically using Grep and Read operations to confirm that your target method names and parameters align with the actual source code definitions.

What are the constraints and mandatory rules for testing OnDirtyLayoutWrapperSwap methods?

Constraints for testing OnDirtyLayoutWrapperSwap methods include enforcing direct method invocation, avoiding magic numbers by using named constants, and completing a mandatory self-checklist to validate branch coverage and test quality.

Can I use standard templates to start writing unit tests for NG Component patterns?

You can use standard templates to start writing unit tests for NG Component patterns by referencing the provided test template files, which offer concrete structures for invoking target methods and setting up clean test baselines.