text
stringlengths 1
474
|
|---|
_counter++;
|
});
|
}
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
appBar: AppBar(
|
title: Text(widget.title),
|
),
|
body: Center(
|
child: Column(
|
mainAxisAlignment: MainAxisAlignment.center,
|
children: <Widget>[
|
const Text(
|
'You have pushed the button this many times:',
|
),
|
Text(
|
'$_counter',
|
style: Theme.of(context).textTheme.headlineMedium,
|
),
|
],
|
),
|
),
|
floatingActionButton: FloatingActionButton(
|
// Provide a Key to this button. This allows finding this
|
// specific button inside the test suite, and tapping it.
|
key: const Key('increment'),
|
onPressed: _incrementCounter,
|
tooltip: 'Increment',
|
child: const Icon(Icons.add),
|
),
|
);
|
}
|
}<code_end>
|
<topic_end>
|
<topic_start>
|
2. Add the integration_test dependency
|
Next, use the integration_test and flutter_test packages
|
to write integration tests. Add these dependencies to the dev_dependencies
|
section of the app’s pubspec.yaml file.<topic_end>
|
<topic_start>
|
3. Create the test files
|
Create a new directory, integration_test, with an empty app_test.dart file:<topic_end>
|
<topic_start>
|
4. Write the integration test
|
Now you can write tests. This involves three steps:
|
<code_start>import 'package:flutter/material.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
import 'package:integration_test/integration_test.dart';
|
import 'package:introduction/main.dart';
|
void main() {
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
group('end-to-end test', () {
|
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('1'), findsOneWidget);
|
});
|
});
|
}<code_end>
|
<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 testsThere 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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.