R003: 禁止恒真断言

Detect tautological assertions in OpenHarmony test files and report violations.

31|6|Updated Jan 29, 2026
One-click install
npx skills add https://github.com/openharmonyinsight/openharmony-skills --skill r003
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: R003: 禁止恒真断言
Source: https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/check-test-code-quality/rules/R003
Command: npx skills add https://github.com/openharmonyinsight/openharmony-skills --skill r003

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

It prevents test cases from containing恒真断言 (tautological assertions) like expect(true).assertTrue() that always succeed and therefore provide no real verification of the system behavior.

Core Features & Use Cases

  • Tautology detection in test assertions: Flags expect(true).assertTrue(), expect(true).assertEqual(true), and expect(false).assertFalse() patterns to avoid ineffective tests.
  • Precise issue reporting: Produces file, line number, and the surrounding test case name (it() block) so failures can be fixed quickly.
  • Actionable remediation guidance: Suggests replacing tautological assertions with assertions on actual values returned by the code under test.

Use case example: When reviewing ArkTS/Javascript unit tests for OpenHarmony, quickly locate and fix thousands of tests that currently “pass” without validating real API outputs, then improve meaningful coverage.

Quick Start

Use the R003 rule to scan your test source files for恒真断言 and output a report listing each violation with its test case name and a suggested replacement.

Frequently Asked Questions about R003: 禁止恒真断言

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

FAQPage Schema
How do I detect tautological assertions in ArkTS or TypeScript unit tests?

To detect tautological assertions in ArkTS or TypeScript unit tests, scan source files ending in .ets, .ts, or .js for patterns like expect(true).assertTrue(). The scan reports each violation with the file path, line number, and surrounding it() block name.

What are tautological assertions and why do they harm test quality?

Tautological assertions are test checks like expect(true).assertEqual(true) that always pass regardless of actual system behavior. They harm test quality by providing no real verification, creating false confidence that code is validated when tests effectively validate nothing.

How do I find useless test cases that always pass in OpenHarmony test code?

To find useless test cases that always pass in OpenHarmony test code, scan for mandated tautology patterns including expect(false).assertFalse(). The scan matches these patterns within it() testcase blocks and returns structured findings with offending snippets and precise fix suggestions.

Does tautology detection work with .ets, .ts, and .js files in OpenHarmony projects?

Tautology detection works with .ets, .ts, and .js files in OpenHarmony projects. The scanning mechanism targets all source files within test contexts, specifically identifying tautological assertion violations across these three file extensions.

How do I fix expect(true).assertTrue() statements in my test cases?

To fix expect(true).assertTrue() statements, replace the hardcoded boolean with an assertion on actual values returned by the code under test. The detection output provides a precise remediation suggestion for replacing the tautology with meaningful API output validation.

Can I scan all source files to report tautological assertion violations with line numbers?

You can scan all source files to report tautological assertion violations with line numbers. The scan outputs structured findings including the exact file path, line number, testcase name, offending snippet, and a suggested replacement for each violation found.