Expose ability to pump() and pumpAndSettle() from IDE while debugging widget tests
- Lenguaje dominante
- Dart
- Estrellas
- 1.7k
- Forks
- 404
- Merge medio
- 6 d 17 h
- PR fusionados (30 d)
- 18
Descripción
`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.
Guía de contribución
Línea de trabajo
Comienza revisando la propuesta del issue y el flujo existente de depuración de widget tests en Flutter; el payload no identifica archivos, tests ni puntos de entrada. Define la acción de pump interactiva y cómo debe comportarse al depurar widget tests. Se considera terminado cuando el IDE expone controles análogos a pump() y pumpAndSettle() que permiten a los usuarios vaciar microtareas y programar un frame.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- dart, flutter
- Área
- devtools, testing-qa
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100