> ## Documentation Index
> Fetch the complete documentation index at: https://bun.zhcndoc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 Bun 测试运行器将测试标记为“todo”

为了提醒自己稍后编写测试，可以使用 `test.todo` 函数。无需提供测试实现。

```ts test.ts icon="https://mintcdn.com/bun-zhcndoc/cnUTwgMuf4cCrwC-/icons/typescript.svg?fit=max&auto=format&n=cnUTwgMuf4cCrwC-&q=85&s=e7767043c9e885c34f2d6c8fe2a95217" theme={"theme":{"light":"github-light","dark":"dracula"}}
import { test, expect } from "bun:test";

// 稍后编写此测试
test.todo("未实现的功能");
```

***

`bun test` 的输出会显示遇到了多少个 `todo` 测试。

```sh terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun test
```

```txt theme={"theme":{"light":"github-light","dark":"dracula"}}
test.test.ts:
✓ add [0.03ms]
✓ multiply [0.02ms]
✎ 未实现的功能

 2 通过
 1 待办
 0 失败
 2 次 expect() 调用
共运行 3 个测试，涉及 1 个文件。 [74.00ms]
```

***

也可以选择提供测试实现。

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
import { test, expect } from "bun:test";

test.todo("未实现的功能", () => {
  expect(Bun.isAwesome()).toBe(true);
});
```

***

如果提供了实现，除非传递了 `--todo` 标志，否则它不会被执行。如果传递了 `--todo` 标志，测试将被执行，并且测试运行器**预期其失败**！如果 todo 测试通过，`bun test` 运行将返回非零退出码以表示失败。

```sh terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun test --todo
```

```txt theme={"theme":{"light":"github-light","dark":"dracula"}}
my.test.ts:
✗ 未实现的功能
  ^ 此测试标记为todo但通过了。请移除 `.todo` 或检查测试是否正确。

 0 通过
 1 失败
 1 次 expect() 调用
$ echo $?
1 # 这是前一个命令的退出代码
```

***

另见：

* [跳过测试](/guides/test/skip-tests)
* [文档 > 测试运行器 > 编写测试](/test/writing-tests)
