Expose ability to pump() and pumpAndSettle() from IDE while debugging widget tests
- Lingua principale
- Dart
- Stelle
- 1.7k
- Fork
- 404
- Merge medio
- 6g 17h
- PR unite (30g)
- 18
Descrizione
`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.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.