text stringlengths 1 474 |
|---|
without running the app itself. An integration test (also |
called end-to-end testing or GUI testing) runs the full app.Hosts and targetsDuring development, you are probably writing the code |
on a desktop computer, called the host machine, |
and running the app on a mobile device, browser, |
or desktop application, called the target device. |
(If you are using a web |
browser or desktop application, |
the host machine is also the target device.)integration_testTests written with the integration_test package can:Migrating from flutter_driverExisting projects using flutter_driver can be migrated to |
integration_test by following the Migrating from flutter_drive |
guide.<topic_end> |
<topic_start> |
Project setup |
Add integration_test and flutter_test to your pubspec.yaml file:In your project, create a new directory |
integration_test with a new file, <name>_test.dart: |
<code_start>import 'package:flutter/material.dart'; |
import 'package:flutter_test/flutter_test.dart'; |
import 'package:how_to/main.dart'; |
import 'package:integration_test/integration_test.dart'; |
void main() { |
testWidgets('tap on the floating action button, verify counter', |
(tester) async { |
// Load app widget. |
await tester.pumpWidget(const MyApp()); |
// Verify the counter starts at 0. |
expect(find.text('0'), findsOneWidget); |
// Finds the floating action button to tap on. |
final fab = find.byKey(const Key('increment')); |
// Emulate a tap on the floating action button. |
await tester.tap(fab); |
// Trigger a frame. |
await tester.pumpAndSettle(); |
// Verify the counter increments by 1. |
expect(find.text('0'), findsNothing); |
expect(find.text('1'), findsOneWidget); |
}); |
}<code_end> |
info Note |
Only use testWidgets to declare your tests. |
Otherwise, Flutter could report errors incorrectly.If you are looking for more examples, take a look at the testing_app of |
the samples repository.<topic_end> |
<topic_start> |
Directory structure |
See also:<topic_end> |
<topic_start> |
Running using the flutter command |
These tests can be launched with the |
flutter test command, where <DEVICE_ID>: |
is the optional device ID or pattern displayed |
in the output of the flutter devices command:This runs the tests in foo_test.dart. To run all tests in this directory on |
the default device, run:<topic_end> |
<topic_start> |
Running in a browser |
Download and install ChromeDriver |
and run it on port 4444:To run tests with flutter drive, create a new directory containing a new file, |
test_driver/integration_test.dart: |
<code_start>import 'package:integration_test/integration_test_driver.dart'; |
Future<void> main() => integrationDriver();<code_end> |
Then add IntegrationTestWidgetsFlutterBinding.ensureInitialized() in your |
integration_test/<name>_test.dart file: |
<code_start>import 'package:flutter/material.dart'; |
import 'package:flutter_test/flutter_test.dart'; |
import 'package:how_to/main.dart'; |
import 'package:integration_test/integration_test.dart'; |
void main() { |
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); // NEW |
testWidgets('tap on the floating action button, verify counter', |
(tester) async { |
// Load app widget. |
await tester.pumpWidget(const MyApp()); |
// Verify the counter starts at 0. |
expect(find.text('0'), findsOneWidget); |
// Finds the floating action button to tap on. |
final fab = find.byKey(const Key('increment')); |
// Emulate a tap on the floating action button. |
await tester.tap(fab); |
// Trigger a frame. |
await tester.pumpAndSettle(); |
// Verify the counter increments by 1. |
expect(find.text('0'), findsNothing); |
expect(find.text('1'), findsOneWidget); |
}); |
}<code_end> |
In a separate process, run flutter_drive:To learn more, see the |
Running Flutter driver tests with web wiki page.<topic_end> |
<topic_start> |
Testing on Firebase Test Lab |
You can use the Firebase Test Lab with both Android |
and iOS targets.<topic_end> |
<topic_start> |
Android setup |
Follow the instructions in the Android Device Testing |
section of the README.<topic_end> |
<topic_start> |
iOS setup |
Follow the instructions in the iOS Device Testing |
section of the README.<topic_end> |
<topic_start> |
Test Lab project setup |
Go to the Firebase Console, |
and create a new project if you don’t have one |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.