Testing in Flutter

Sep 19 2023 · Dart 2.19.3, Flutter 3.7.6, Android Studio 2021.3.1, Visual Studio Code 1.7.4

Part 3: Write Widget Tests

09. Write Login Widget Test

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 08. Mock API Requests Next episode: 10. Find & Pump Widget

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Now that we are done with unit tests let’s explore widget testing. The main goal of widget testing is to test the application’s UI and check if it’s getting rendered as intended. The main difference between a Widget Test and an Integration Test is that in Widget Test, you are testing the application’s UI, and in Integration Test you are testing the UI and the functionality of the application.

void main() {

}
import 'package:flutter_test/flutter_test.dart';

void main() {

  testWidgets('Login Widget Test', (WidgetTester tester) async {

  });
}
testWidgets('Login Widget Test', (WidgetTester tester) async {
  await tester.pumpWidget(LoginScreen());
  expect(find.text('Login Screen'), findsOneWidget);
});
testWidgets('Login Widget Test', (WidgetTester tester) async {
  await tester.pumpWidget(MaterialApp(home: LoginScreen()));
  expect(find.text('Login Screen'), findsOneWidget);
});
 testWidgets('Login Widget Test', (WidgetTester tester) async {
    await tester.pumpWidget(
      ProviderScope(
        child: MaterialApp(
          home: LoginScreen(),
        ),
      ),
    );
    expect(find.text('Login Screen'), findsOneWidget);
  });