text
stringlengths 1
372
|
|---|
expect(find.text('hi'), findsNothing);
|
});
|
<code_end>
|
<topic_end>
|
<topic_start>
|
complete example
|
<code_start>
|
import 'package:flutter/material.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
void main() {
|
testWidgets('Add and remove a todo', (tester) async {
|
// build the widget.
|
await tester.pumpWidget(const TodoList());
|
// enter 'hi' into the TextField.
|
await tester.enterText(find.byType(TextField), 'hi');
|
// tap the add button.
|
await tester.tap(find.byType(FloatingActionButton));
|
// rebuild the widget with the new item.
|
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.