text stringlengths 1 474 |
|---|
await tester.pump(); |
// Expect to find the item on screen. |
expect(find.text('hi'), findsOneWidget); |
// Swipe the item to dismiss it. |
await tester.drag(find.byType(Dismissible), const Offset(500, 0)); |
// Build the widget until the dismiss animation ends. |
await tester.pumpAndSettle(); |
// Ensure that the item is no longer on screen. |
expect(find.text('hi'), findsNothing); |
}); |
} |
class TodoList extends StatefulWidget { |
const TodoList({super.key}); |
@override |
State<TodoList> createState() => _TodoListState(); |
} |
class _TodoListState extends State<TodoList> { |
static const _appTitle = 'Todo List'; |
final todos = <String>[]; |
final controller = TextEditingController(); |
@override |
Widget build(BuildContext context) { |
return MaterialApp( |
title: _appTitle, |
home: Scaffold( |
appBar: AppBar( |
title: const Text(_appTitle), |
), |
body: Column( |
children: [ |
TextField( |
controller: controller, |
), |
Expanded( |
child: ListView.builder( |
itemCount: todos.length, |
itemBuilder: (context, index) { |
final todo = todos[index]; |
return Dismissible( |
key: Key('$todo$index'), |
onDismissed: (direction) => todos.removeAt(index), |
background: Container(color: Colors.red), |
child: ListTile(title: Text(todo)), |
); |
}, |
), |
), |
], |
), |
floatingActionButton: FloatingActionButton( |
onPressed: () { |
setState(() { |
todos.add(controller.text); |
controller.clear(); |
}); |
}, |
child: const Icon(Icons.add), |
), |
), |
); |
} |
}<code_end> |
<topic_end> |
<topic_start>An introduction to integration testing |
Unit tests and widget tests are handy for testing individual classes, |
functions, or widgets. However, they generally don’t test how |
individual pieces work together as a whole, or capture the performance |
of an application running on a real device. These tasks are performed |
with integration tests.Integration tests are written using the integration_test package, provided |
by the SDK.In this recipe, learn how to test a counter app. It demonstrates |
how to set up integration tests, how to verify specific text is displayed |
by the app, how to tap specific widgets, and how to run integration tests.This recipe uses the following steps:<topic_end> |
<topic_start> |
1. Create an app to test |
First, create an app for testing. In this example, |
test the counter app produced by the flutter create |
command. This app allows a user to tap on a button |
to increase a counter. |
<code_start>import 'package:flutter/material.dart'; |
void main() => runApp(const MyApp()); |
class MyApp extends StatelessWidget { |
const MyApp({super.key}); |
@override |
Widget build(BuildContext context) { |
return const MaterialApp( |
title: 'Counter App', |
home: MyHomePage(title: 'Counter App Home Page'), |
); |
} |
} |
class MyHomePage extends StatefulWidget { |
const MyHomePage({super.key, required this.title}); |
final String title; |
@override |
State<MyHomePage> createState() => _MyHomePageState(); |
} |
class _MyHomePageState extends State<MyHomePage> { |
int _counter = 0; |
void _incrementCounter() { |
setState(() { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.