flutter / flutter/devtools

Expose ability to pump() and pumpAndSettle() from IDE while debugging widget tests

未关闭
#2,150 18 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看
P3 screen: debugger
主要语言
Dart
星标
1.7k
派生
404
平均合并
6 天 17 小时
30 天内合并 PR
18

描述

`pump([Duration])` and `pumpAndSettle()` are poorly understood APIs in Flutter widget testing. Most often, when a test unexpectedly fails, the users simple add pumps until it passes.

One such example we had in Greentea goes like this. Imagine the following API for model layer:

```dart
// Sub methods
sub();
unsub();

// Returns null if result is not cached and initiates a "fill" call.
// Returns result if it was cached.
ModelResult getResult({params});

// You then use this in a stateful widget:

initState() => sub();
dispose() => unsub();

Widget build(BuildContext context) {
final result = getResult(params);
if (result == null) {
// Render loading indicator
} else {
// Render UI.
}
}
```

This is pretty straight forward in a normal execution flow. When it came to testing, we replaced all model services such that the fill call would immediate return a mock result. That however, required an extra microtask to execute because the initial result would always be null until the fill method got called.

Because real code is not as simple as above and some of the logic was buried under different abstractions, it took us a while to realize that an extra pump() was needed in order to get the actual widget rendered.

There are many cases like this where the widget author might not even be aware of what's going in the model layer and how many pumps are needed.

One idea that might help is to provide an interactive pump() button. The pump button would be similar to "Step" button in a debugger except it would just flush microtasks and schedule a frame.

贡献指南

打开贡献指南

调研方向

首先查看 issue 提案和现有的 Flutter widget test 调试流程;payload 未指定文件、测试或入口点。定义交互式 pump 操作,以及在调试 widget test 时该操作应如何运行。完成标准是 IDE 提供类似于 pump() 和 pumpAndSettle() 的控件,使用户能够刷新 microtasks 并调度一个 frame。

由索引模型根据 Issue 内容生成。

评估

技术栈
dart, flutter
领域
devtools, testing-qa
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。