text stringlengths 1 372 |
|---|
<topic_end> |
<topic_start> |
5. run the integration test |
the process of running the integration tests varies depending on the platform |
you are testing against. you can test against a mobile platform or the web. |
<topic_end> |
<topic_start> |
5a. mobile |
to test on a real iOS / android device, first connect the device and run the |
following command from the root of the project: |
or, you can specify the directory to run all integration tests: |
this command runs the app and integration tests on the target device. for more |
information, see the integration testing page. |
<topic_end> |
<topic_start> |
5b. web |
to get started testing in a web browser, download ChromeDriver. |
next, create a new directory named test_driver containing a new file |
named integration_test.dart: |
<code_start> |
import 'package:integration_test/integration_test_driver.dart'; |
future<void> main() => integrationDriver(); |
<code_end> |
launch chromedriver as follows: |
from the root of the project, run the following command: |
for a headless testing experience, you can also run flutter drive |
with web-server as the target device identifier as follows: |
<topic_end> |
<topic_start> |
integration testing |
this page describes how to use the integration_test package to run |
integration tests. tests written using this package have the following |
properties: |
info note |
the integration_test package is part of the flutter SDK itself. |
to use it, make sure that you update your app’s pubspec file |
to include this package as one of your dev_dependencies. |
for an example, see the project setup section below. |
<topic_end> |
<topic_start> |
overview |
unit tests, widget tests, and integration tests |
there are three types of tests that flutter supports. |
a unit test verifies the behavior of a method or class. |
a widget test verifies the behavior of flutter widgets |
without running the app itself. an integration test (also |
called end-to-end testing or GUI testing) runs the full app. |
hosts and targets |
during 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_test |
tests written with the integration_test package can: |
migrating from flutter_driver |
existing 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: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.