write-rust-tests

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Write Rust Tests

编写Rust测试

Write new Rust tests for Rust code.
为Rust代码编写新的Rust测试。

Arguments

参数

  • <path>
    : Path to the Rust crate or file.
  • <path 1> <path 2>
    : Multiple crate/file paths.
If a path doesn't include
src/
, assume it to be in the
src/redisearch_rs
directory. E.g.
numeric_range_tree
becomes
src/redisearch_rs/numeric_range_tree
. If a path points to a directory, consider all Rust files in that directory.
  • <path>
    : Rust crate或文件的路径。
  • <path 1> <path 2>
    : 多个crate/文件路径。
如果路径不包含
src/
,则默认其位于
src/redisearch_rs
目录下。例如,
numeric_range_tree
会被视为
src/redisearch_rs/numeric_range_tree
。 如果路径指向一个目录,则包含该目录下的所有Rust文件。

Guidelines

指南

The generated tests must follow the guidelines outlined in /rust-tests-guidelines.
生成的测试必须遵循/rust-tests-guidelines中列出的指南。

What to test

测试内容

Ensure that all public APIs are tested thoroughly, including edge cases, error conditions and branches. Use
/check-rust-coverage
to determine which lines are not covered by tests.
确保所有公共API都经过全面测试,包括边缘情况、错误条件和分支。 使用/check-rust-coverage来确定哪些代码行未被测试覆盖。

Avoiding redundant tests

避免冗余测试

Before writing each test, explicitly identify which branch or code path it will cover that no existing test already covers. An uncovered line is not sufficient justification — ask why it is uncovered and whether it is reachable through an already-tested entry point.
Two tests are redundant if they exercise the same set of branches in the code under test. Differing only in input values that don't change control flow is not a distinct scenario.
Do not write standalone tests for:
  • Trivial trait delegations
    Default
    ,
    From
    , or similar trait impls that are single-line delegations to an already-tested constructor, since they will be covered transitively.
After adding tests, double check that every new test covers at least one branch that no other test (existing or new) covers. Remove any that don't.
在编写每个测试之前,明确确定它将覆盖哪些现有测试未覆盖的分支或代码路径。仅存在未覆盖的代码行并不足以作为理由——要询问为什么它未被覆盖,以及是否可以通过已测试的入口点到达该代码行。
如果两个测试在被测代码中执行相同的分支集合,则它们是冗余的。仅输入值不同但不改变控制流的情况不属于不同场景。
请勿为以下内容编写独立测试:
  • 简单 trait 委托 ——
    Default
    From
    或类似的trait实现,这些实现是单行委托给已测试的构造函数,因为它们会被间接覆盖。
添加测试后,再次检查每个新测试是否至少覆盖了一个其他测试(现有或新添加的)未覆盖的分支。移除不符合要求的测试。