text
stringlengths
1
474
pretty: true,
includeSummary: true,
);
}
},
);
}<code_end>
The integrationDriver function has a responseDataCallback
which you can customize.
By default, it writes the results to the integration_response_data.json file,
but you can customize it to generate a summary like in this example.<topic_end>
<topic_start>
4. Run the test
After configuring the test to capture a performance Timeline and save a
summary of the results to disk, run the test with the following command:The --profile option means to compile the app for the “profile mode”
rather than the “debug mode”, so that the benchmark result is closer to
what will be experienced by end users.info Note
Run the command with --no-dds when running on a mobile device or emulator.
This option disables the Dart Development Service (DDS), which won’t
be accessible from your computer.<topic_end>
<topic_start>
5. Review the results
After the test completes successfully, the build directory at the root of
the project contains two files:<topic_end>
<topic_start>Summary example
<topic_end>
<topic_start>
Complete example
integration_test/scrolling_test.dart
<code_start>import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:scrolling/main.dart';
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('Counter increments smoke test', (tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp(
items: List<String>.generate(10000, (i) => 'Item $i'),
));
final listFinder = find.byType(Scrollable);
final itemFinder = find.byKey(const ValueKey('item_50_text'));
await binding.traceAction(
() async {
// Scroll until the item to be found appears.
await tester.scrollUntilVisible(
itemFinder,
500.0,
scrollable: listFinder,
);
},
reportKey: 'scrolling_timeline',
);
});
}<code_end>
test_driver/perf_driver.dart
<code_start>import 'package:flutter_driver/flutter_driver.dart' as driver;
import 'package:integration_test/integration_test_driver.dart';
Future<void> main() {
return integrationDriver(
responseDataCallback: (data) async {
if (data != null) {
final timeline = driver.Timeline.fromJson(
data['scrolling_timeline'] as Map<String, dynamic>,
);
// Convert the Timeline into a TimelineSummary that's easier to
// read and understand.
final summary = driver.TimelineSummary.summarize(timeline);
// Then, write the entire timeline to disk in a json format.
// This file can be opened in the Chrome browser's tracing tools
// found by navigating to chrome://tracing.
// Optionally, save the summary to disk by setting includeSummary
// to true
await summary.writeTimelineToFile(
'scrolling_timeline',
pretty: true,
includeSummary: true,
);
}
},
);
}<code_end>
<topic_end>
<topic_start>Testing plugins
All of the usual types of Flutter tests apply to
plugin packages as well, but because plugins contain
native code they often also require other kinds of tests
to test all of their functionality.info Note
To learn how to test your plugin code, read on.
To learn how to avoid crashes from a plugin when
testing your Flutter app, check out
Plugins in Flutter tests.<topic_end>
<topic_start>
Types of plugin tests
To see examples of each of these types of tests, you can
create a new plugin from the plugin template
and look in the indicated directories.Dart unit tests and widget tests.
These tests allow you to test the Dart portion of your plugin
just as you would test the Dart code of a non-plugin package.
However, the plugin’s native code won’t be loaded,