搜索分类、插件与代码仓

插件详情v1.3.3

fake_async

用于确定性测试的假异步事件,例如计时器和微任务。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1030万
喜欢数
123
Pub 分数
150

安装插件

flutter pub add fake_async

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

fake_async 是一个用于异步代码确定性测试的 Dart 包。它允许开发者在受控环境中模拟计时器、微任务和其他异步事件,确保测试结果可预测且可重复。通过模拟异步行为,它消除了对真实时间延迟的依赖,使测试更快且更可靠。非常适合涉及异步操作(如 futures、streams 或计划任务)的单元测试和集成测试。

适合场景

  • 测试异步代码而不使用实际延迟
  • 模拟计时器和微任务
  • 编写确定性单元测试
  • 验证流和未来逻辑
  • 提高测试性能

主要特点

  • 控制异步操作的时机
  • 支持微任务和定时器伪造
  • 启用精确的测试执行
  • 与测试包集成
  • 提供用于异步模拟的干净 API

适合对象

  • Dart 开发人员编写单元测试
  • 优先考虑测试可靠性的团队
  • 具有复杂异步工作流的项目
  • 测试驱动开发实践
  • 需要快速测试的CI/CD流水线

使用建议

  • 不适用于端到端测试
  • 需要理解事件循环
  • 仅限测试环境
  • 不会在生产环境中替代真实的异步行为
  • 测试文件中需要正确设置

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Dart CI OpenSSF Scorecard

What's here?

Welcome! package:test is the standard testing library for Dart and Flutter. If you have questions about Dart testing, please see the docs for package:test. package:test_api and package:test_core are implementation details and generally not user-facing.

package:checks is a relatively new library for expressing test expectations. It's a more modern version of package:matcher and features a literate API.

Packages

Package Description Issues Version
checks A framework for checking values against expectations and building custom expectations. issues pub package
fake_async Fake asynchronous events such as timers and microtasks for deterministic testing. issues pub package
matcher Support for specifying test expectations via an extensible Matcher class. Also includes a number of built-in Matcher implementations for common cases. issues pub package
test A full featured library for writing and running Dart tests across platforms. issues pub package
test_api The user facing API for structuring Dart tests and checking expectations. pub package
test_core A basic library for writing tests and running them on the VM. pub package
test_descriptor An API for defining and verifying files and directory structures. issues pub package
test_process Test processes: starting; validating stdout and stderr; checking exit code. issues pub package

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目