mirror of
https://github.com/flutter/flutter.git
synced 2026-02-11 05:17:36 +08:00
This makes it possible to substitute 'flutter run' for 'flutter test'
and actually watch a test run on a device.
For any test that depends on flutter_test:
1. Remove any import of 'package:test/test.dart'.
2. Replace `testWidgets('...', (WidgetTester tester) {`
with `testWidgets('...', (WidgetTester tester) async {`
3. Add an "await" in front of calls to any of the following:
* tap()
* tapAt()
* fling()
* flingFrom()
* scroll()
* scrollAt()
* pump()
* pumpWidget()
4. Replace any calls to `tester.flushMicrotasks()` with calls to
`await tester.idle()`.
There's a guarding API that you can use, if you have particularly
complicated tests, to get better error messages. Search for
TestAsyncUtils.
25 lines
1.5 KiB
Dart
25 lines
1.5 KiB
Dart
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
test('FlutterError.defaultStackFilter', () {
|
|
List<String> filtered = FlutterError.defaultStackFilter(StackTrace.current.toString().trimRight().split('\n')).toList();
|
|
expect(filtered.length, 4);
|
|
expect(filtered[0], matches(r'^#0 +main\.<anonymous closure> \(.*stack_trace_test\.dart:[0-9]+:[0-9]+\)$'));
|
|
expect(filtered[1], matches(r'^#1 +Declarer\.test\.<anonymous closure>\.<<anonymous closure>_async_body>\.<anonymous closure>\.<<anonymous closure>_async_body> \(package:test/.+:[0-9]+:[0-9]+\)$'));
|
|
expect(filtered[2], matches(r'^#[1-9][0-9]+ +Declarer\._runSetUps\.<_runSetUps_async_body> \(package:test/.+:[0-9]+:[0-9]+\)$'));
|
|
expect(filtered[3], matches(r'^\(elided [1-9][0-9]+ frames from package dart:async, package dart:async-patch, and package stack_trace\)$'));
|
|
});
|
|
|
|
test('FlutterError.defaultStackFilter (async test body)', () async {
|
|
List<String> filtered = FlutterError.defaultStackFilter(StackTrace.current.toString().trimRight().split('\n')).toList();
|
|
expect(filtered.length, 2);
|
|
expect(filtered[0], matches(r'^#0 +main\.<anonymous closure>\.<<anonymous closure>_async_body> \(.*stack_trace_test\.dart:[0-9]+:[0-9]+\)$'));
|
|
expect(filtered[1], matches(r'^\(elided [1-9][0-9]+ frames from package dart:async and package stack_trace\)$'));
|
|
});
|
|
}
|