Introduction
Testing helps find mistakes early so the app works well. It makes sure the app does what it should every time.
Testing helps find mistakes early so the app works well. It makes sure the app does what it should every time.
test('description', () { // test code here });
Use the test function to write a test case with a description.
Inside the test, check if the app behaves as expected.
test('sum of 2 and 3 is 5', () { expect(2 + 3, 5); });
test('string contains hello', () { expect('hello world'.contains('hello'), true); });
This simple test checks if 10 is greater than 5, which should be true.
import 'package:flutter_test/flutter_test.dart'; void main() { test('Check if 10 is greater than 5', () { expect(10 > 5, true); }); }
Write small tests that check one thing at a time.
Run tests often to catch problems early.
Good tests save time and make your app more reliable.
Testing finds errors before users see them.
Tests confirm the app works as expected.
Regular testing helps keep the app reliable and stable.
testWidgets('Check button', (tester) async {
await tester.pumpWidget(MaterialApp(home: Scaffold(body: TextButton(onPressed: () {}, child: Text('Press')))));
expect(find.text('Press'), findsOneWidget);
expect(find.byType(TextButton), findsOneWidget);
});testWidgets('Check text', (tester) async {
await tester.pumpWidget(MaterialApp(home: Scaffold(body: Text('Hello'))));
expect(find.text('Hi'), findsOneWidget);
});Pass the test and this pattern moves unknown