-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
a: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our teststoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Description
Using WidgetTest.pump(elapsedTime) to advance animations and completions in a test can be difficult because just calling the function once doesn't necessarily roll all of the test's state forward by the specified time. The unit test below illustrates a simple version of the problem: it's necessary to call pump(1 second) twice to get the 200ms performance from one end to the other. More complex widgets, see for example snack_bar_test.dart, require more blind test pumping.
import 'package:flutter/animation.dart';
import 'package:flutter/widgets.dart';
import 'package:test/test.dart';
import 'widget_tester.dart';
void main() {
test('Time does not move', () {
testWidgets((WidgetTester tester) {
tester.pumpWidget(new Container());
Performance performance = new Performance(duration: const Duration(milliseconds: 200))
..forward();
print("performance.progress=${performance.progress} expect 0.0");
tester.pump(new Duration(seconds: 1));
print("performance.progress=${performance.progress} expect 1.0");
tester.pump(new Duration(seconds: 1));
print("performance.progress=${performance.progress} is actually 1.0");
performance.reverse();
tester.pump(new Duration(seconds: 1));
print("performance.progress=${performance.progress} expect 0.0");
tester.pump(new Duration(seconds: 1));
print("performance.progress=${performance.progress} is actualy 0.0");
});
});
}
Metadata
Metadata
Assignees
Labels
a: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our teststoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.