For AI agents: the complete documentation index is available at https://rstest.rs/zh/llms.txt, the full documentation bundle is available at https://rstest.rs/zh/llms-full.txt, and this page is available as Markdown at https://rstest.rs/zh/config/test/repeats.md.
close
  • 简体中文
  • repeats

    • 类型: number
    • 默认值: 0
    • CLI: --repeats <times>

    单个测试的额外执行次数,可用于复现偶发失败。设置 repeats: 2 时,每个通过的测试总共执行三次。重复以单个测试为单位,不会重跑整个文件或套件:串行测试 A 和 B 的执行顺序为 A, A, A, B, B, B。

    每次执行都会运行 beforeEach / afterEach,以及测试级 fixture 的初始化和清理。测试模块和 beforeAll / afterAll 不会随每轮重复执行。

    npx rstest run --repeats 2
    rstest.config.ts
    import { defineConfig } from '@rstest/core';
    
    export default defineConfig({
      repeats: 2,
    });

    优先级从高到低依次为:测试自身的 TestOptions.repeats > 最近的 describe 默认值 > run({ repeats }) 参数或 CLI --repeats 参数 > 配置中的值 > 默认值 0。

    在测试或套件上设置 { repeats: 0 },可以关闭继承的重复执行。

    每轮重复都有独立的 retry 配额。某轮用尽重试次数后仍然失败,该测试就会失败,并停止后续重复。未开启 retry 时,首次失败就会停止该测试的后续重复。